• winform 制作圆形图片框


     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 Circle
    27         {
    28             get
    29             {
    30                 return _circle;
    31             }
    32 
    33             set
    34             {
    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 CircleSize
    50         {
    51             get
    52             {
    53                 return _circleSize;
    54             }
    55             set
    56             {
    57                 _circleSize = value;
    58                 Circle = true;
    59             }
    60         }
    61     }
  • 相关阅读:
    机器学习【工具】:Numpy
    机器学习【算法】:KNN近邻
    【笔记】:字典内部剖析
    【笔记】:谁偷了我的内存?
    什么是RESTful框架
    音频下载服务
    【模块】:Requests(二)
    【模块】:Weakref
    异步Web服务(二)
    【Win10】UAP/UWP/通用 开发之 RelativePanel
  • 原文地址:https://www.cnblogs.com/jieliu726/p/4674336.html
Copyright © 2020-2023  润新知