1 public partial class CirclePictureBox : PictureBox 2 { 3 public CirclePictureBox() 4 { 5 Circle = true; 6 InitializeComponent(); 7 } 8 9 protected override void OnPaint(PaintEventArgs pe)10 { 11 base.OnPaint(pe); 12 }13 14 //圆形大小随控件大小变化15 protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified)16 {17 if (width > 0 && height > 0)18 {19 CircleSize = new Size(width, height);20 }21 base.SetBoundsCore(x, y, width, height, specified);22 }23 24 bool _circle;25 [Description(" 获取或设置按钮椭圆效果。"), DefaultValue(true)]26 public bool Circle27 {28 get29 {30 return _circle;31 }32 33 set34 {35 if (value)36 {37 GraphicsPath gp = new GraphicsPath();38 gp.AddEllipse(0, 0, _circleSize.Width, _circleSize.Height);//圆形 39 this.Region = new Region(gp);40 this.BorderStyle = BorderStyle.None;41 this.Invalidate();42 }43 _circle = value;44 }45 }46 47 Size _circleSize=new Size(50,50);48 [Description(" 圆形的大小")]49 Size CircleSize50 {51 get52 {53 return _circleSize;54 }55 set56 {57 _circleSize = value;58 Circle = true;59 }60 }61 }