110,499
社区成员
发帖
与我相关
我的任务
分享
public partial class ShapeButton : Button
{
public ShapeButton()
{
InitializeComponent();
}
protected override void OnPaint(PaintEventArgs pe)
{
base.OnPaint(pe);
}
bool flag;
[Description(" 获取或设置按钮椭圆效果。"), DefaultValue(false)]
public bool Circle
{
set
{
flag = value;
GraphicsPath gp = new GraphicsPath();
gp.AddEllipse(this.ClientRectangle);//圆形
this.Region = new Region(gp);
FlatAppearance.BorderSize = 0;//去掉边框
FlatStyle = System.Windows.Forms.FlatStyle.Flat;
BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(128)))), ((int)(((byte)(255)))));//背景颜色
this.Invalidate();
}
get { return flag; }
}
}
在winform窗体添加了一个shapeButton,然后在属性窗体修改Circle属性为true,就可以改变button的形状