前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >(三十七)c#Winform自定义控件-有标题的面板

(三十七)c#Winform自定义控件-有标题的面板

作者头像
冰封一夏
发布2019-09-11 16:52:48
6550
发布2019-09-11 16:52:48
举报
文章被收录于专栏:c#Winform自定义控件系列

前提

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

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

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

目录

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

准备工作

用到了控件基类 UCControlBase,如果你还不了解UCControlBase,请移步 (一)c#Winform自定义控件-基类控件 查看

开始

添加一个用户控件,命名UCPanelTitle,继承自UCControlBase

2个属性  

代码语言:javascript
复制
 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         }

全部代码

代码语言:javascript
复制
 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 }
代码语言:javascript
复制
 1 namespace HZH_Controls.Controls
 2 {
 3     partial class UCPanelTitle
 4     {
 5         /// <summary> 
 6         /// 必需的设计器变量。
 7         /// </summary>
 8         private System.ComponentModel.IContainer components = null;
 9 
10         /// <summary> 
11         /// 清理所有正在使用的资源。
12         /// </summary>
13         /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
14         protected override void Dispose(bool disposing)
15         {
16             if (disposing && (components != null))
17             {
18                 components.Dispose();
19             }
20             base.Dispose(disposing);
21         }
22 
23         #region 组件设计器生成的代码
24 
25         /// <summary> 
26         /// 设计器支持所需的方法 - 不要
27         /// 使用代码编辑器修改此方法的内容。
28         /// </summary>
29         private void InitializeComponent()
30         {
31             this.lblTitle = new System.Windows.Forms.Label();
32             this.SuspendLayout();
33             // 
34             // lblTitle
35             // 
36             this.lblTitle.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(22)))), ((int)(((byte)(160)))), ((int)(((byte)(133)))));
37             this.lblTitle.Dock = System.Windows.Forms.DockStyle.Top;
38             this.lblTitle.ForeColor = System.Drawing.Color.White;
39             this.lblTitle.Location = new System.Drawing.Point(0, 0);
40             this.lblTitle.Name = "lblTitle";
41             this.lblTitle.Size = new System.Drawing.Size(432, 34);
42             this.lblTitle.TabIndex = 0;
43             this.lblTitle.Text = "面板";
44             this.lblTitle.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
45             // 
46             // UCPanelTitle
47             // 
48             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
49             this.BackColor = System.Drawing.Color.Transparent;
50             this.ConerRadius = 10;
51             this.Controls.Add(this.lblTitle);
52             this.FillColor = System.Drawing.Color.White;
53             this.IsRadius = true;
54             this.IsShowRect = true;
55             this.Name = "UCPanelTitle";
56             this.RectColor = System.Drawing.Color.FromArgb(((int)(((byte)(22)))), ((int)(((byte)(160)))), ((int)(((byte)(133)))));
57             this.Size = new System.Drawing.Size(432, 301);
58             this.ResumeLayout(false);
59 
60         }
61 
62         #endregion
63 
64         private System.Windows.Forms.Label lblTitle;
65     }
66 }

用处及效果

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019-08-17 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 前提
  • 目录
  • 准备工作
  • 开始
  • 用处及效果
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档