Windows窗体中的圆形RadioButton列表

我使用jquery 插件和html在Web应用程序中设计了循环按钮列表。 在这个设计用户中,一次只选择单选按钮列表。 设计如下:

在此处输入图像描述

如何在Windows窗体中实现相同的设计和function? 请帮助我,从我开始实现这一目标。

在Windows窗体中有多个选项可以执行此操作。 作为选项,您可以从自定义RadioButtonPanel控件开始。 您可以创建一个派生自Panel的新类和一个派生自RadioButton的新类,然后重写这些类的OnPaint方法并绘制所需的表示。

以下是我在此帖中分享的示例实现的结果:

在此处输入图像描述

自定义面板

 public class MyPanel : Panel { public MyPanel() { this.Padding = new Padding(2); } protected override void OnPaint(PaintEventArgs e) { e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; using (var path = new GraphicsPath()) { var d = this.Padding.All; var r = this.Height - 2 * d; path.AddArc(d, d, r, r, 90, 180); path.AddArc(this.Width - r - d, d, r, r, -90, 180); path.CloseFigure(); using (var pen = new Pen(Color.Silver, d)) e.Graphics.DrawPath(pen, path); } } } 

自定义单选按钮

 public class MyRadioButton : RadioButton { public MyRadioButton() { this.Appearance = System.Windows.Forms.Appearance.Button; this.BackColor = Color.Transparent; this.TextAlign = ContentAlignment.MiddleCenter; this.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.FlatAppearance.BorderColor = Color.RoyalBlue; this.FlatAppearance.BorderSize = 2; } protected override void OnPaint(PaintEventArgs e) { this.OnPaintBackground(e); using (var path = new GraphicsPath()) { var c = e.Graphics.ClipBounds; var r = this.ClientRectangle; r.Inflate(-FlatAppearance.BorderSize, -FlatAppearance.BorderSize); path.AddEllipse(r); e.Graphics.SetClip(path); base.OnPaint(e); e.Graphics.SetClip(c); e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias; if (this.Checked) { using (var p = new Pen(FlatAppearance.BorderColor, FlatAppearance.BorderSize)) { e.Graphics.DrawEllipse(p, r); } } } } } 

要求使用

 using System; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; 

Hii Gopal你可以使用自定义控件来实现这个function.Goodluck请参考这些链接

  1. 如何定制像这样的按钮控制?

  2. https://msdn.microsoft.com/en-us/library/h4te2zh2(v=vs.90).aspx

  3. 如何在Winform C#上创建带圆角/边缘的按钮?

您可以从列表视图或列表框开始将项目模板更改为按钮,并根据需要为按钮添加样式。 将列表视图的选择模式设置为Single。