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

(八十五)c#Winform自定义控件-引用区块

时间:2019-10-15 09:48:20      阅读:109      评论:0      收藏:0      [点我收藏+]

标签:category   control   tee   void   https   ted   this   tle   设置   

前提

入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章。

GitHub:https://github.com/kwwwvagaa/NetWinformControl

码云:https://gitee.com/kwwwvagaa/net_winform_custom_control.git

如果觉得写的还行,请点个 star 支持一下吧

欢迎前来交流探讨: 企鹅群568015492 技术图片

来都来了,点个【推荐】再走吧,谢谢

NuGet

Install-Package HZH_Controls

目录

https://www.cnblogs.com/bfyx/p/11364884.html

用处及效果

技术图片

准备工作

没什么可准备的,直接往下看吧

开始

添加一个类UCPanelQuote继承 Panel

添加2个属性

 1 /// <summary>
 2         /// The border color
 3         /// </summary>
 4         private Color borderColor = LineColors.Light;
 5 
 6         /// <summary>
 7         /// Gets or sets the color of the border.
 8         /// </summary>
 9         /// <value>The color of the border.</value>
10         [Description("边框颜色"), Category("自定义")]
11         public Color BorderColor
12         {
13             get { return borderColor; }
14             set
15             {
16                 borderColor = value;
17                 this.Invalidate();
18             }
19         }
20 
21         /// <summary>
22         /// The left color
23         /// </summary>
24         private Color leftColor = StatusColors.Danger;
25 
26         /// <summary>
27         /// Gets or sets the color of the left.
28         /// </summary>
29         /// <value>The color of the left.</value>
30         [Description("左侧颜色"), Category("自定义")]
31         public Color LeftColor
32         {
33             get { return leftColor; }
34             set
35             {
36                 leftColor = value;
37                 this.Invalidate();
38             }
39         }

为了画边框和左边的颜色,设置一下Padding

1    public UCPanelQuote()
2             : base()
3         {
4             Padding = new Padding(5, 1, 1, 1);
5         }

重绘

 1 protected override void OnPaint(PaintEventArgs e)
 2         {
 3             base.OnPaint(e);
 4             e.Graphics.SetGDIHigh();
 5 
 6             e.Graphics.DrawLines(new Pen(borderColor), new Point[] 
 7             { 
 8                 new Point(e.ClipRectangle.Left,e.ClipRectangle.Top),
 9                 new Point(e.ClipRectangle.Right-1,e.ClipRectangle.Top),
10                 new Point(e.ClipRectangle.Right-1,e.ClipRectangle.Bottom-1),
11                 new Point(e.ClipRectangle.Left,e.ClipRectangle.Bottom-1),
12                 new Point(e.ClipRectangle.Left,e.ClipRectangle.Top)
13             });
14 
15             e.Graphics.FillRectangle(new SolidBrush(leftColor), new Rectangle(0, 0, 5, this.Height));
16         }

 

最后的话

如果你喜欢的话,请到 https://gitee.com/kwwwvagaa/net_winform_custom_control 点个星星吧

(八十五)c#Winform自定义控件-引用区块

标签:category   control   tee   void   https   ted   this   tle   设置   

原文地址:https://www.cnblogs.com/bfyx/p/11675488.html

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