* UINavMenu: 修改了一处可能的出错
This commit is contained in:
parent
fe2e06f506
commit
ec8e1a73df
Binary file not shown.
@ -80,6 +80,12 @@ namespace Sunny.UI
|
||||
SetScrollInfo();
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
tmpFont?.Dispose();
|
||||
}
|
||||
|
||||
[Browsable(false)]
|
||||
public bool IsScaled { get; private set; }
|
||||
|
||||
@ -623,8 +629,7 @@ namespace Sunny.UI
|
||||
|
||||
if (ShowTips && MenuHelper.GetTipsText(e.Node).IsValid() && TreeNodeSymbols.NotContainsKey(e.Node))
|
||||
{
|
||||
var tmpFont = this.DPIScaleFont(TipsFont);
|
||||
SizeF tipsSize = e.Graphics.MeasureString(MenuHelper.GetTipsText(e.Node), tmpFont);
|
||||
SizeF tipsSize = e.Graphics.MeasureString(MenuHelper.GetTipsText(e.Node), TempFont);
|
||||
float sfMax = Math.Max(tipsSize.Width, tipsSize.Height) + 1;
|
||||
float tipsLeft = Width - (ScrollBarVisible ? ScrollBarInfo.VerticalScrollBarWidth() : 0) - sfMax - sfMax;
|
||||
float tipsTop = e.Bounds.Y + (ItemHeight - sfMax) / 2;
|
||||
@ -635,20 +640,34 @@ namespace Sunny.UI
|
||||
if (MenuHelper[e.Node].TipsCustom)
|
||||
{
|
||||
e.Graphics.FillEllipse(MenuHelper[e.Node].TipsBackColor, tipsLeft, tipsTop, sfMax, sfMax);
|
||||
e.Graphics.DrawString(MenuHelper.GetTipsText(e.Node), tmpFont, MenuHelper[e.Node].TipsForeColor, new RectangleF(tipsLeft, tipsTop, sfMax, sfMax), alignment);
|
||||
e.Graphics.DrawString(MenuHelper.GetTipsText(e.Node), TempFont, MenuHelper[e.Node].TipsForeColor, new RectangleF(tipsLeft, tipsTop, sfMax, sfMax), alignment);
|
||||
}
|
||||
else
|
||||
{
|
||||
e.Graphics.FillEllipse(TipsColor, tipsLeft, tipsTop, sfMax, sfMax);
|
||||
e.Graphics.DrawString(MenuHelper.GetTipsText(e.Node), tmpFont, TipsForeColor, new RectangleF(tipsLeft, tipsTop, sfMax, sfMax), alignment);
|
||||
e.Graphics.DrawString(MenuHelper.GetTipsText(e.Node), TempFont, TipsForeColor, new RectangleF(tipsLeft, tipsTop, sfMax, sfMax), alignment);
|
||||
}
|
||||
}
|
||||
|
||||
tmpFont.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Font tmpFont;
|
||||
|
||||
private Font TempFont
|
||||
{
|
||||
get
|
||||
{
|
||||
if (tmpFont == null || !tmpFont.Size.EqualsFloat(TipsFont.DPIScaleFontSize()))
|
||||
{
|
||||
tmpFont?.Dispose();
|
||||
tmpFont = this.DPIScaleFont(TipsFont);
|
||||
}
|
||||
|
||||
return tmpFont;
|
||||
}
|
||||
}
|
||||
|
||||
private Color tipsColor = Color.Red;
|
||||
|
||||
[DefaultValue(typeof(Color), "Red"), Category("SunnyUI"), Description("节点提示圆点背景颜色")]
|
||||
|
@ -32,24 +32,6 @@ namespace Sunny.UI
|
||||
return control.CreateGraphics().DpiX / 96.0f;
|
||||
}
|
||||
|
||||
public static Font DPIScaleFont(this Control control, Font font)
|
||||
{
|
||||
if (UIStyles.DPIScale)
|
||||
{
|
||||
if (font.GdiCharSet == 134)
|
||||
return new Font(font.FontFamily, font.Size / control.DPIScale(), font.Style, font.Unit, font.GdiCharSet);
|
||||
else
|
||||
return new Font(font.FontFamily, font.Size / control.DPIScale());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (font.GdiCharSet == 134)
|
||||
return new Font(font.FontFamily, font.Size, font.Style, font.Unit, font.GdiCharSet);
|
||||
else
|
||||
return new Font(font.FontFamily, font.Size);
|
||||
}
|
||||
}
|
||||
|
||||
public static float DPIScaleFontSize(this Control control, Font font)
|
||||
{
|
||||
if (UIStyles.DPIScale)
|
||||
@ -59,12 +41,22 @@ namespace Sunny.UI
|
||||
}
|
||||
|
||||
public static float DPIScaleFontSize(this Font font)
|
||||
{
|
||||
return font.Size.DPIScaleFontSize();
|
||||
}
|
||||
|
||||
public static float DPIScaleFontSize(this float fontSize)
|
||||
{
|
||||
using Control control = new();
|
||||
if (UIStyles.DPIScale)
|
||||
return font.Size / control.DPIScale();
|
||||
return fontSize / control.DPIScale();
|
||||
else
|
||||
return font.Size;
|
||||
return fontSize;
|
||||
}
|
||||
|
||||
public static Font DPIScaleFont(this Control control, Font font)
|
||||
{
|
||||
return control.DPIScaleFont(font, font.Size);
|
||||
}
|
||||
|
||||
public static Font DPIScaleFont(this Control control, Font font, float fontSize)
|
||||
|
Loading…
x
Reference in New Issue
Block a user