From 45d2eed8b91e0d4b0d11193a53a40f05d40d1ba9 Mon Sep 17 00:00:00 2001 From: Sunny Date: Wed, 30 Oct 2024 21:46:30 +0800 Subject: [PATCH] =?UTF-8?q?*=20UIPage:=20=E5=A2=9E=E5=8A=A0=E6=A0=87?= =?UTF-8?q?=E9=A2=98=E6=A0=8F=E5=9B=BE=E7=89=87=E5=B1=9E=E6=80=A7IconImage?= =?UTF-8?q?=EF=BC=8C=E4=BC=98=E5=85=88=E4=BA=8ESymbol?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SunnyUI/Frames/UIPage.cs | 42 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/SunnyUI/Frames/UIPage.cs b/SunnyUI/Frames/UIPage.cs index 10a6719c..7a0ba63f 100644 --- a/SunnyUI/Frames/UIPage.cs +++ b/SunnyUI/Frames/UIPage.cs @@ -44,6 +44,7 @@ * 2023-12-04: V3.6.1 修复修改Style后,BackColor未保存的问题 * 2023-12-20: V3.6.2 调整AfterShow事件位置及逻辑 * 2024-04-28: V3.6.5 增加WindowStateChanged事件 + * 2024-10-30: V3.7.2 增加标题栏图片属性IconImage,优先于Symbol ******************************************************************************/ using System; @@ -89,6 +90,35 @@ namespace Sunny.UI base.SizeGripStyle = SizeGripStyle.Hide; } + private Image iconImage = null; + + [Description("标题栏图标图片,状态栏显示仍然用Icon属性"), Category("SunnyUI")] + [DefaultValue(null)] + public Image IconImage + { + get => iconImage; + set + { + iconImage = value; + Invalidate(); + } + } + + private int iconImageSize = 24; + + [Description("标题栏图标图片大小"), Category("SunnyUI")] + [DefaultValue(24)] + public int IconImageSize + { + get => iconImageSize; + set + { + iconImageSize = Math.Max(16, value); + iconImageSize = Math.Min(titleHeight - 2, iconImageSize); + Invalidate(); + } + } + public readonly Guid Guid = Guid.NewGuid(); private Color _rectColor = UIColor.Blue; @@ -663,12 +693,20 @@ namespace Sunny.UI } if (!AllowShowTitle) return; - if (Symbol > 0) + + int titleLeft = ImageInterval; + if (IconImage != null) + { + e.Graphics.DrawImage(IconImage, new Rectangle(6, (TitleHeight - IconImageSize) / 2 + 1, IconImageSize, IconImageSize), new Rectangle(0, 0, IconImage.Width, IconImage.Height), GraphicsUnit.Pixel); + titleLeft = ImageInterval + IconImageSize + 2; + } + else if (Symbol > 0) { e.Graphics.DrawFontImage(Symbol, SymbolSize, TitleForeColor, new Rectangle(ImageInterval, 0, SymbolSize, TitleHeight), SymbolOffset.X, SymbolOffset.Y, SymbolRotate); + titleLeft = ImageInterval + SymbolSize + 2; } - e.Graphics.DrawString(Text, TitleFont, TitleForeColor, new Rectangle(Symbol > 0 ? ImageInterval * 2 + SymbolSize : ImageInterval, 0, Width, TitleHeight), ContentAlignment.MiddleLeft); + e.Graphics.DrawString(Text, TitleFont, TitleForeColor, new Rectangle(titleLeft, 0, Width, TitleHeight), ContentAlignment.MiddleLeft); e.Graphics.SetHighQuality(); if (ControlBox)