前提
入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章。
GitHub:https://github.com/kwwwvagaa/NetWinformControl
码云:https://gitee.com/kwwwvagaa/net_winform_custom_control.git
如果觉得写的还行,请点个 star 支持一下吧
目录
https://www.cnblogs.com/bfyx/p/11364884.html
准备工作
用到了控件基类 UCControlBase,如果你还不了解UCControlBase,请移步 (一)c#Winform自定义控件-基类控件 查看
开始
添加一个用户控件,命名UCPanelTitle,继承自UCControlBase
2个属性
1 [Description("边框颜色"), Category("自定义")] 2 public Color BorderColor 3 { 4 get { return this.RectColor; } 5 set 6 { 7 this.RectColor = value; 8 this.lblTitle.BackColor = value; 9 } 10 } 11 12 [Description("面板标题"), Category("自定义")] 13 public string Title 14 { 15 get { return lblTitle.Text; } 16 set { lblTitle.Text = value; } 17 }
全部代码
1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Drawing; 5 using System.Data; 6 using System.Linq; 7 using System.Text; 8 using System.Windows.Forms; 9 10 namespace HZH_Controls.Controls 11 { 12 public partial class UCPanelTitle : UCControlBase 13 { 14 [Description("边框颜色"), Category("自定义")] 15 public Color BorderColor 16 { 17 get { return this.RectColor; } 18 set 19 { 20 this.RectColor = value; 21 this.lblTitle.BackColor = value; 22 } 23 } 24 25 [Description("面板标题"), Category("自定义")] 26 public string Title 27 { 28 get { return lblTitle.Text; } 29 set { lblTitle.Text = value; } 30 } 31 public UCPanelTitle() 32 { 33 InitializeComponent(); 34 } 35 } 36 }