前提
入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章。
GitHub:https://github.com/kwwwvagaa/NetWinformControl
码云:https://gitee.com/kwwwvagaa/net_winform_custom_control.git
如果觉得写的还行,请点个 star 支持一下吧
来都来了,点个【推荐】再走吧,谢谢
NuGet
Install-Package HZH_Controls
目录
https://www.cnblogs.com/bfyx/p/11364884.html
用处及效果
准备工作
这个比较简单,对label扩展,重绘划线即可
开始
添加一个类UCSplitLabel ,继承 Label
代码比较少
1 // *********************************************************************** 2 // Assembly : HZH_Controls 3 // Created : 2019-10-09 4 // 5 // *********************************************************************** 6 // <copyright file="UCSplitLabel.cs"> 7 // Copyright by Huang Zhenghui(黄正辉) All, QQ group:568015492 QQ:623128629 Email:623128629@qq.com 8 // </copyright> 9 // 10 // Blog: https://www.cnblogs.com/bfyx 11 // GitHub:https://github.com/kwwwvagaa/NetWinformControl 12 // gitee:https://gitee.com/kwwwvagaa/net_winform_custom_control.git 13 // 14 // If you use this code, please keep this note. 15 // *********************************************************************** 16 using System; 17 using System.Collections.Generic; 18 using System.Linq; 19 using System.Text; 20 using System.Windows.Forms; 21 using System.Drawing; 22 using System.ComponentModel; 23 24 namespace HZH_Controls.Controls 25 { 26 /// <summary> 27 /// Class UCSplitLabel. 28 /// Implements the <see cref="System.Windows.Forms.Label" /> 29 /// </summary> 30 /// <seealso cref="System.Windows.Forms.Label" /> 31 public class UCSplitLabel : Label 32 { 33 /// <summary> 34 /// Gets or sets the text. 35 /// </summary> 36 /// <value>The text.</value> 37 [Localizable(true)] 38 public override string Text 39 { 40 get 41 { 42 return base.Text; 43 } 44 set 45 { 46 base.Text = value; 47 ResetMaxSize(); 48 } 49 } 50 /// <summary> 51 /// 获取或设置控件显示的文字的字体。 52 /// </summary> 53 /// <value>The font.</value> 54 /// <PermissionSet> 55 /// <IPermission class="System.Security.Permissions.EnvironmentPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" /> 56 /// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" /> 57 /// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode, ControlEvidence" /> 58 /// <IPermission class="System.Diagnostics.PerformanceCounterPermission, System, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" /> 59 /// </PermissionSet> 60 [Localizable(true)] 61 public override Font Font 62 { 63 get 64 { 65 return base.Font; 66 } 67 set 68 { 69 base.Font = value; 70 ResetMaxSize(); 71 } 72 } 73 /// &l