+ UIMarkLabel:增加带颜色标签的Label

This commit is contained in:
Sunny 2021-03-07 19:40:27 +08:00
parent 7a2f2b498c
commit 71049bfff3
12 changed files with 220 additions and 2 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -35,11 +35,21 @@
this.uiLine3 = new Sunny.UI.UILine();
this.uiSymbolLabel1 = new Sunny.UI.UISymbolLabel();
this.uiSymbolLabel2 = new Sunny.UI.UISymbolLabel();
this.uiMarkLabel1 = new Sunny.UI.UIMarkLabel();
this.uiLine4 = new Sunny.UI.UILine();
this.uiMarkLabel2 = new Sunny.UI.UIMarkLabel();
this.uiMarkLabel3 = new Sunny.UI.UIMarkLabel();
this.uiMarkLabel4 = new Sunny.UI.UIMarkLabel();
this.PagePanel.SuspendLayout();
this.SuspendLayout();
//
// PagePanel
//
this.PagePanel.Controls.Add(this.uiMarkLabel4);
this.PagePanel.Controls.Add(this.uiMarkLabel3);
this.PagePanel.Controls.Add(this.uiMarkLabel2);
this.PagePanel.Controls.Add(this.uiLine4);
this.PagePanel.Controls.Add(this.uiMarkLabel1);
this.PagePanel.Controls.Add(this.uiSymbolLabel2);
this.PagePanel.Controls.Add(this.uiSymbolLabel1);
this.PagePanel.Controls.Add(this.uiLine3);
@ -113,6 +123,7 @@
//
this.uiSymbolLabel1.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiSymbolLabel1.Location = new System.Drawing.Point(42, 209);
this.uiSymbolLabel1.MinimumSize = new System.Drawing.Size(1, 1);
this.uiSymbolLabel1.Name = "uiSymbolLabel1";
this.uiSymbolLabel1.Padding = new System.Windows.Forms.Padding(28, 0, 0, 0);
this.uiSymbolLabel1.Size = new System.Drawing.Size(91, 24);
@ -124,6 +135,7 @@
//
this.uiSymbolLabel2.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiSymbolLabel2.Location = new System.Drawing.Point(139, 209);
this.uiSymbolLabel2.MinimumSize = new System.Drawing.Size(1, 1);
this.uiSymbolLabel2.Name = "uiSymbolLabel2";
this.uiSymbolLabel2.Padding = new System.Windows.Forms.Padding(28, 0, 0, 0);
this.uiSymbolLabel2.Size = new System.Drawing.Size(91, 24);
@ -132,6 +144,64 @@
this.uiSymbolLabel2.Text = "Cancel";
this.uiSymbolLabel2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// uiMarkLabel1
//
this.uiMarkLabel1.AutoSize = true;
this.uiMarkLabel1.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiMarkLabel1.Location = new System.Drawing.Point(42, 285);
this.uiMarkLabel1.Name = "uiMarkLabel1";
this.uiMarkLabel1.Padding = new System.Windows.Forms.Padding(5, 0, 0, 0);
this.uiMarkLabel1.Size = new System.Drawing.Size(118, 21);
this.uiMarkLabel1.TabIndex = 24;
this.uiMarkLabel1.Text = "uiMarkLabel1";
//
// uiLine4
//
this.uiLine4.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiLine4.Location = new System.Drawing.Point(30, 248);
this.uiLine4.MinimumSize = new System.Drawing.Size(16, 16);
this.uiLine4.Name = "uiLine4";
this.uiLine4.Size = new System.Drawing.Size(670, 20);
this.uiLine4.TabIndex = 25;
this.uiLine4.Text = "UIMarkLabel";
this.uiLine4.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// uiMarkLabel2
//
this.uiMarkLabel2.AutoSize = true;
this.uiMarkLabel2.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiMarkLabel2.Location = new System.Drawing.Point(42, 326);
this.uiMarkLabel2.MarkPos = Sunny.UI.UIMarkLabel.UIMarkPos.Bottom;
this.uiMarkLabel2.Name = "uiMarkLabel2";
this.uiMarkLabel2.Padding = new System.Windows.Forms.Padding(0, 0, 0, 5);
this.uiMarkLabel2.Size = new System.Drawing.Size(113, 26);
this.uiMarkLabel2.TabIndex = 26;
this.uiMarkLabel2.Text = "uiMarkLabel2";
//
// uiMarkLabel3
//
this.uiMarkLabel3.AutoSize = true;
this.uiMarkLabel3.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiMarkLabel3.Location = new System.Drawing.Point(185, 285);
this.uiMarkLabel3.MarkPos = Sunny.UI.UIMarkLabel.UIMarkPos.Right;
this.uiMarkLabel3.Name = "uiMarkLabel3";
this.uiMarkLabel3.Padding = new System.Windows.Forms.Padding(0, 0, 5, 0);
this.uiMarkLabel3.Size = new System.Drawing.Size(118, 21);
this.uiMarkLabel3.TabIndex = 27;
this.uiMarkLabel3.Text = "uiMarkLabel3";
//
// uiMarkLabel4
//
this.uiMarkLabel4.AutoSize = true;
this.uiMarkLabel4.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiMarkLabel4.Location = new System.Drawing.Point(190, 326);
this.uiMarkLabel4.MarkPos = Sunny.UI.UIMarkLabel.UIMarkPos.Top;
this.uiMarkLabel4.Name = "uiMarkLabel4";
this.uiMarkLabel4.Padding = new System.Windows.Forms.Padding(0, 5, 0, 0);
this.uiMarkLabel4.Size = new System.Drawing.Size(113, 26);
this.uiMarkLabel4.TabIndex = 28;
this.uiMarkLabel4.Text = "uiMarkLabel4";
//
// FLabel
//
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 21F);
@ -156,5 +226,10 @@
private UILine uiLine1;
private UISymbolLabel uiSymbolLabel1;
private UISymbolLabel uiSymbolLabel2;
private UIMarkLabel uiMarkLabel1;
private UILine uiLine4;
private UIMarkLabel uiMarkLabel4;
private UIMarkLabel uiMarkLabel3;
private UIMarkLabel uiMarkLabel2;
}
}

View File

@ -25,6 +25,7 @@ using System.Drawing.Design;
using System.Security.Permissions;
using System.Windows.Forms;
using System.Windows.Forms.Design;
#pragma warning disable SYSLIB0003 // 类型或成员已过时
namespace Sunny.UI
{

View File

@ -26,6 +26,7 @@ using System.Runtime.InteropServices;
using System.Security.Permissions;
using System.Windows.Forms;
using System.Windows.Forms.Design;
#pragma warning disable SYSLIB0003 // 类型或成员已过时
namespace Sunny.UI
{

View File

@ -87,10 +87,9 @@ namespace Sunny.UI
[Description("获取或设置可以自定义主题风格"), Category("SunnyUI")]
public bool StyleCustomMode { get; set; }
public void SetStyleColor(UIBaseStyle uiColor)
public virtual void SetStyleColor(UIBaseStyle uiColor)
{
if (uiColor.IsCustom()) return;
ForeColor = uiColor.LabelForeColor;
Invalidate();
}

View File

@ -0,0 +1,140 @@
/******************************************************************************
* SunnyUI
* CopyRight (C) 2012-2021 ShenYongHua().
* QQ群56829229 QQ17612584 EMailSunnyUI@QQ.Com
*
* Blog: https://www.cnblogs.com/yhuse
* Gitee: https://gitee.com/yhuse/SunnyUI
* GitHub: https://github.com/yhuse/SunnyUI
*
* SunnyUI.dll can be used for free under the GPL-3.0 license.
* If you use this code, please keep this note.
* 使
******************************************************************************
* : UIMarkLabel.cs
* :
* : V3.0
* : 2021-03-07
*
* 2021-03-07: V3.0.2
******************************************************************************/
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
namespace Sunny.UI
{
public class UIMarkLabel : UILabel
{
public UIMarkLabel()
{
Padding = new Padding(MarkSize + 2, 0, 0, 0);
}
private bool autoSize;
[Browsable(true)]
[Description("自动大小"), Category("SunnyUI")]
public override bool AutoSize
{
get => autoSize;
set
{
autoSize = value;
Invalidate();
}
}
private int markSize = 3;
[Description("标签大小"), Category("SunnyUI"), DefaultValue(3)]
public int MarkSize
{
get => markSize;
set
{
markSize = value;
Invalidate();
}
}
private UIMarkPos markPos = UIMarkPos.Left;
[Description("标签位置"), Category("SunnyUI"), DefaultValue(UIMarkPos.Left)]
public UIMarkPos MarkPos
{
get => markPos;
set
{
markPos = value;
switch (markPos)
{
case UIMarkPos.Left: Padding = new Padding(MarkSize + 2, 0, 0, 0); break;
case UIMarkPos.Right: Padding = new Padding(0, 0, MarkSize + 2, 0); break;
case UIMarkPos.Top: Padding = new Padding(0, MarkSize + 2, 0, 0); break;
case UIMarkPos.Bottom: Padding = new Padding(0, 0, 0, MarkSize + 2); break;
}
Invalidate();
}
}
public enum UIMarkPos
{
Left,
Top,
Right,
Bottom
}
private Color markColor = UIColor.Blue;
[Description("标签颜色"), Category("SunnyUI")]
[DefaultValue(typeof(Color), "80, 160, 255")]
public Color MarkColor
{
get => markColor;
set
{
markColor = value;
Invalidate();
}
}
public override void SetStyleColor(UIBaseStyle uiColor)
{
base.SetStyleColor(uiColor);
if (uiColor.IsCustom()) return;
markColor = uiColor.PrimaryColor;
Invalidate();
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
SizeF TextSize = e.Graphics.MeasureString(Text, Font);
if (autoSize)
{
float width = (MarkPos == UIMarkPos.Left || MarkPos == UIMarkPos.Right) ?
TextSize.Width + MarkSize + 2 : TextSize.Width;
float height = (MarkPos == UIMarkPos.Top || MarkPos == UIMarkPos.Bottom) ?
TextSize.Height + MarkSize + 2 : TextSize.Height;
if (Width != (int)width) Width = (int)width;
if (Height != (int)height) Height = (int)height;
}
switch (markPos)
{
case UIMarkPos.Left: e.Graphics.FillRectangle(MarkColor, 0, 0, MarkSize, Height); break;
case UIMarkPos.Right: e.Graphics.FillRectangle(MarkColor, Width - MarkSize, 0, MarkSize, Height); break;
case UIMarkPos.Top: e.Graphics.FillRectangle(MarkColor, 0, 0, Width, MarkSize); break;
case UIMarkPos.Bottom: e.Graphics.FillRectangle(MarkColor, 0, Height - MarkSize, Width, MarkSize); break;
}
}
}
}

View File

@ -24,6 +24,7 @@ using System.ComponentModel;
using System.Media;
using System.Security;
using System.Security.Permissions;
#pragma warning disable SYSLIB0003 // 类型或成员已过时
namespace Sunny.UI
{

View File

@ -4,6 +4,7 @@ using System.Text;
using HANDLE = System.IntPtr;
using HDC = System.IntPtr;
using HWND = System.IntPtr;
#pragma warning disable CS0618 // 类型或成员已过时
namespace Sunny.UI.Win32
{