winform 制作圆形图片框

 public partial class CirclePictureBox : PictureBox
     {
         public CirclePictureBox()
         {
             Circle = true;
             InitializeComponent();
         }        

         protected override void OnPaint(PaintEventArgs pe)
         {
             base.OnPaint(pe);
         }

         //圆形大小随控件大小变化
         protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified)
         {
              && height > )
             {
                 CircleSize = new Size(width, height);
             }
             base.SetBoundsCore(x, y, width, height, specified);
         }

         bool _circle;
         [Description(" 获取或设置按钮椭圆效果。"), DefaultValue(true)]
         public bool Circle
         {
             get
             {
                 return _circle;
             }

             set
             {
                 if (value)
                 {
                     GraphicsPath gp = new GraphicsPath();
                     gp.AddEllipse(, , _circleSize.Width, _circleSize.Height);//圆形
                     this.Region = new Region(gp);
                     this.BorderStyle = BorderStyle.None;
                     this.Invalidate();
                 }
                 _circle = value;
             }
         }

         Size _circleSize=,);
         [Description(" 圆形的大小")]
         Size CircleSize
         {
             get
             {
                 return _circleSize;
             }
             set
             {
                 _circleSize = value;
                 Circle = true;
             }
         }
     }
上一篇:【BZOJ-4562】食物链 记忆化搜索(拓扑序 + DP)


下一篇:洛谷 P3183 [HAOI2016]食物链 题解