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     }

 

转载于:https://www.cnblogs.com/jieliu726/p/4674336.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值