premise
It's been 7 or 8 years, and I've always wanted to make a beautiful set of custom controls, so I've got this series of articles.
GitHub: https://github.com/kwwwvagaa/NetWinformControl
Code cloud: https://gitee.com/kwwwvagaa/net_winform_custom_control.git
If you think it's OK, please click star to support it.
Welcome to exchange and discuss: Penguins 568015492
Catalog
https://blog.csdn.net/kwwwvagaa/article/details/100586547
Preparation
UCControlBase is used. If you don't know UCControlBase, please move on. (1) c#Winform Custom Control - Base Class Control View
start
Add a user control named UCPanelTitle, inherited from UCControlBase
Two attributes
1 [Description("Border color"), Category("custom")] 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("Panel title"), Category("custom")] 13 public string Title 14 { 15 get { return lblTitle.Text; } 16 set { lblTitle.Text = value; } 17 }
All code
using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Windows.Forms; namespace HZH_Controls.Controls { public partial class UCPanelTitle : UCControlBase { [Description("Border color"), Category("custom")] public Color BorderColor { get { return this.RectColor; } set { this.RectColor = value; this.lblTitle.BackColor = value; } } [Description("Panel title"), Category("custom")] public string Title { get { return lblTitle.Text; } set { lblTitle.Text = value; } } public UCPanelTitle() { InitializeComponent(); } } }
namespace HZH_Controls.Controls { partial class UCPanelTitle { /// <summary> /// Required designer variables. /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// Clean up all resources in use. /// </summary> /// <param name="disposing">true if managed resources should be released; otherwise false. </param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #Code generated by region component designer /// <summary> /// Designer supports required methods - no /// Use the code editor to modify the content of this method. /// </summary> private void InitializeComponent() { this.lblTitle = new System.Windows.Forms.Label(); this.SuspendLayout(); // // lblTitle // this.lblTitle.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(22)))), ((int)(((byte)(160)))), ((int)(((byte)(133))))); this.lblTitle.Dock = System.Windows.Forms.DockStyle.Top; this.lblTitle.ForeColor = System.Drawing.Color.White; this.lblTitle.Location = new System.Drawing.Point(0, 0); this.lblTitle.Name = "lblTitle"; this.lblTitle.Size = new System.Drawing.Size(432, 34); this.lblTitle.TabIndex = 0; this.lblTitle.Text = "panel"; this.lblTitle.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; // // UCPanelTitle // this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; this.BackColor = System.Drawing.Color.Transparent; this.ConerRadius = 10; this.Controls.Add(this.lblTitle); this.FillColor = System.Drawing.Color.White; this.IsRadius = true; this.IsShowRect = true; this.Name = "UCPanelTitle"; this.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(22)))), ((int)(((byte)(160)))), ((int)(((byte)(133))))); this.Size = new System.Drawing.Size(432, 301); this.ResumeLayout(false); } #endregion private System.Windows.Forms.Label lblTitle; } }
Utility and effect
Last words
If you like, please go to https://gitee.com/kwwwvagaa/net_winform_custom_control Spot a star.