Windows 表单中的圆形单选按钮列表
Circular RadioButton List in Windows Forms
我使用 jquery plugin 和 html 在 Web 应用程序中设计了圆形按钮列表。在这个设计中,用户一次 select 一天只喜欢单选按钮列表。设计如下图:
如何以 windows 形式实现相同的设计和功能?请帮助我,从我要开始实现这一目标的地方。
您可以从列表视图或列表框开始
将项目模板更改为按钮,并根据需要为按钮添加样式。
将列表视图的选择模式设为单选
Hii Gopal 您可以使用自定义实现此功能 control.Goodluck
请参考这些链接
How to customize Button Control like this one?
https://msdn.microsoft.com/en-us/library/h4te2zh2(v=vs.90).aspx
How do I create button with rounded corners/edges on Winform C#?
有多个选项可以在 windows 表单中执行此操作。作为一种选择,您可以从自定义 RadioButton
和 Panel
控件开始。您可以创建一个从 Panel
派生的新 class 和一个从 RadioButton
派生的新 class,然后覆盖那些 class 的 OnPaint
方法和绘制所需的演示文稿。
这是我在此 post 中分享的示例实现的结果:
自定义面板
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;
我使用 jquery plugin 和 html 在 Web 应用程序中设计了圆形按钮列表。在这个设计中,用户一次 select 一天只喜欢单选按钮列表。设计如下图:
如何以 windows 形式实现相同的设计和功能?请帮助我,从我要开始实现这一目标的地方。
您可以从列表视图或列表框开始 将项目模板更改为按钮,并根据需要为按钮添加样式。 将列表视图的选择模式设为单选
Hii Gopal 您可以使用自定义实现此功能 control.Goodluck 请参考这些链接
How to customize Button Control like this one?
https://msdn.microsoft.com/en-us/library/h4te2zh2(v=vs.90).aspx
How do I create button with rounded corners/edges on Winform C#?
有多个选项可以在 windows 表单中执行此操作。作为一种选择,您可以从自定义 RadioButton
和 Panel
控件开始。您可以创建一个从 Panel
派生的新 class 和一个从 RadioButton
派生的新 class,然后覆盖那些 class 的 OnPaint
方法和绘制所需的演示文稿。
这是我在此 post 中分享的示例实现的结果:
自定义面板
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;