码迷,mamicode.com
首页 > Windows程序 > 详细

winform 制作圆形图片框

时间:2015-07-24 20:45:00      阅读:145      评论:0      收藏:0      [点我收藏+]

标签:

 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     }

 

winform 制作圆形图片框

标签:

原文地址:http://www.cnblogs.com/Smile-Jie/p/4674336.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!