c# winform 重写button,让button成为椭圆的

c# winform 重写button,让button变为椭圆的。
c# winform 重写button,让button变为椭圆的。
------解决方案--------------------
Region,这个属性。
------解决方案--------------------
Control.Region 属性

详细例子,请看#3


引用:
http://msdn.microsoft.com/zh-cn/library/vstudio/system.windows.forms.control.region(v=vs.100).aspx

------解决方案--------------------
重写button类,然后使用Region重绘区域

 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的形状
------解决方案--------------------
这个代码,编译后会在控件那个列表里,生成一个控件图标的,你拖动就好了。
------解决方案--------------------
可以使用啊,就是效果差强人意,你再美化吧。
c# winform 重写button,让button成为椭圆的