diff --git a/SunnyUI/Controls/Color/UIHSLColor.cs b/SunnyUI/Controls/Color/UIHSLColor.cs
index 5d841f7e..e1554b79 100644
--- a/SunnyUI/Controls/Color/UIHSLColor.cs
+++ b/SunnyUI/Controls/Color/UIHSLColor.cs
@@ -201,12 +201,13 @@ namespace Sunny.UI
public static void DrawFrame(Graphics dc, RectangleF r, float cornerRadius, Color color)
{
- Pen pen = new Pen(color);
+ using Pen pen = new Pen(color);
if (cornerRadius <= 0)
{
dc.DrawRectangle(pen, Rect(r));
return;
}
+
cornerRadius = (float)Math.Min(cornerRadius, Math.Floor(r.Width) - 2);
cornerRadius = (float)Math.Min(cornerRadius, Math.Floor(r.Height) - 2);
diff --git a/SunnyUI/Controls/UIAnalogMeterRender.cs b/SunnyUI/Controls/UIAnalogMeterRender.cs
index 0c827936..40552097 100644
--- a/SunnyUI/Controls/UIAnalogMeterRender.cs
+++ b/SunnyUI/Controls/UIAnalogMeterRender.cs
@@ -180,11 +180,7 @@ namespace Sunny.UI
Color bodyColor = this.AnalogMeter.BodyColor;
Color cDark = LBColorManager.StepColor(bodyColor, 20);
-
- LinearGradientBrush br1 = new LinearGradientBrush(rc,
- bodyColor,
- cDark,
- 45);
+ using LinearGradientBrush br1 = new LinearGradientBrush(rc, bodyColor, cDark, 45);
Gr.FillEllipse(br1, rc);
float drawRatio = this.AnalogMeter.GetDrawRatio();
@@ -195,10 +191,7 @@ namespace Sunny.UI
_rc.Width -= 6 * drawRatio;
_rc.Height -= 6 * drawRatio;
- LinearGradientBrush br2 = new LinearGradientBrush(_rc,
- cDark,
- bodyColor,
- 45);
+ using LinearGradientBrush br2 = new LinearGradientBrush(_rc, cDark, bodyColor, 45);
Gr.FillEllipse(br2, _rc);
return true;
@@ -234,8 +227,8 @@ namespace Sunny.UI
float radius = (float)(w / 2 - (w * 0.08));
float rulerValue = (float)minValue;
- Pen pen = new Pen(scaleColor, (2 * drawRatio));
- SolidBrush br = new SolidBrush(scaleColor);
+ using Pen pen = new Pen(scaleColor, (2 * drawRatio));
+ using SolidBrush br = new SolidBrush(scaleColor);
PointF ptStart = new PointF(0, 0);
PointF ptEnd = new PointF(0, 0);
@@ -323,7 +316,7 @@ namespace Sunny.UI
PointF ptStart = new PointF(0, 0);
PointF ptEnd = new PointF(0, 0);
- GraphicsPath pth1 = new GraphicsPath();
+ using GraphicsPath pth1 = new GraphicsPath();
ptStart.X = cx;
ptStart.Y = cy;
@@ -346,8 +339,8 @@ namespace Sunny.UI
pth1.CloseFigure();
- SolidBrush br = new SolidBrush(this.AnalogMeter.NeedleColor);
- Pen pen = new Pen(this.AnalogMeter.NeedleColor);
+ using SolidBrush br = new SolidBrush(this.AnalogMeter.NeedleColor);
+ using Pen pen = new Pen(this.AnalogMeter.NeedleColor);
Gr.DrawPath(pen, pth1);
Gr.FillPath(br, pth1);
@@ -367,15 +360,12 @@ namespace Sunny.UI
_rc.Inflate(5 * drawRatio, 5 * drawRatio);
- SolidBrush brTransp = new SolidBrush(clr1);
+ using SolidBrush brTransp = new SolidBrush(clr1);
Gr.FillEllipse(brTransp, _rc);
clr1 = clr;
Color clr2 = LBColorManager.StepColor(clr, 75);
- LinearGradientBrush br1 = new LinearGradientBrush(rc,
- clr1,
- clr2,
- 45);
+ using LinearGradientBrush br1 = new LinearGradientBrush(rc, clr1, clr2, 45);
Gr.FillEllipse(br1, rc);
return true;
}
@@ -389,12 +379,8 @@ namespace Sunny.UI
return true;
Color clr1 = Color.FromArgb(40, 200, 200, 200);
-
Color clr2 = Color.FromArgb(0, 200, 200, 200);
- LinearGradientBrush br1 = new LinearGradientBrush(rc,
- clr1,
- clr2,
- 45);
+ using LinearGradientBrush br1 = new LinearGradientBrush(rc, clr1, clr2, 45);
Gr.FillEllipse(br1, rc);
return true;
diff --git a/SunnyUI/Controls/UIKnobControl.cs b/SunnyUI/Controls/UIKnobControl.cs
index 67d6f1d6..cb8612f5 100644
--- a/SunnyUI/Controls/UIKnobControl.cs
+++ b/SunnyUI/Controls/UIKnobControl.cs
@@ -552,6 +552,16 @@ namespace Sunny.UI
#endregion properties
+ ~UIKnob()
+ {
+ DottedPen?.Dispose();
+ knobFont?.Dispose();
+ brushKnob?.Dispose();
+ brushKnobPointer.Dispose();
+ gOffScreen?.Dispose();
+ OffScreenImage?.Dispose();
+ }
+
public UIKnob()
{
// This call is required by the Windows.Forms Form Designer.
@@ -920,10 +930,10 @@ namespace Sunny.UI
Font font;
- Pen penL = new Pen(_scaleColor, (2 * drawRatio));
- Pen penS = new Pen(_scaleColor, (1 * drawRatio));
+ using Pen penL = new Pen(_scaleColor, (2 * drawRatio));
+ using Pen penS = new Pen(_scaleColor, (1 * drawRatio));
- SolidBrush br = new SolidBrush(_scaleColor);
+ using SolidBrush br = new SolidBrush(_scaleColor);
PointF ptStart = new PointF(0, 0);
PointF ptEnd = new PointF(0, 0);
@@ -978,10 +988,8 @@ namespace Sunny.UI
str = String.Format("{0,0:D}", (int)val);
// If autosize
- if (_scaleFontAutoSize)
- strsize = TextRenderer.MeasureText(str, new Font(_scaleFont.FontFamily, fSize));
- else
- strsize = TextRenderer.MeasureText(str, new Font(_scaleFont.FontFamily, _scaleFont.Size));
+ using Font tmpFont = _scaleFontAutoSize ? new Font(_scaleFont.FontFamily, fSize) : new Font(_scaleFont.FontFamily, _scaleFont.Size);
+ strsize = TextRenderer.MeasureText(str, tmpFont);
if (_drawDivInside)
{
diff --git a/SunnyUI/Controls/UILine.cs b/SunnyUI/Controls/UILine.cs
index 1f675850..f556f1f8 100644
--- a/SunnyUI/Controls/UILine.cs
+++ b/SunnyUI/Controls/UILine.cs
@@ -182,7 +182,7 @@ namespace Sunny.UI
{
SizeF sf = new SizeF(0, 0);
float x = 0;
- Pen pen = new Pen(rectColor, lineSize);
+ using Pen pen = new Pen(rectColor, lineSize);
if (LineDashStyle != UILineDashStyle.None)
{
pen.DashStyle = (DashStyle)((int)LineDashStyle);
@@ -296,8 +296,6 @@ namespace Sunny.UI
int left = (Width - lineSize) / 2;
g.DrawLine(pen, left, Padding.Top, left, Height - Padding.Top - Padding.Bottom);
}
-
- pen.Dispose();
}
UILineDashStyle lineDashStyle = UILineDashStyle.None;
diff --git a/SunnyUI/Controls/UILogo.cs b/SunnyUI/Controls/UILogo.cs
index 07c17de2..e06104d5 100644
--- a/SunnyUI/Controls/UILogo.cs
+++ b/SunnyUI/Controls/UILogo.cs
@@ -74,15 +74,16 @@ namespace Sunny.UI
int len = 60;
x = x + 34;
y = y + 34;
- g.DrawLine(new Pen(BackColor, 2), x, y, x - len, y - len / 2 - 4);
- g.DrawLine(new Pen(BackColor, 2), x, y, x - len, y + len / 2 + 4);
+ using Pen pen = new Pen(BackColor, 2);
+ g.DrawLine(pen, x, y, x - len, y - len / 2 - 4);
+ g.DrawLine(pen, x, y, x - len, y + len / 2 + 4);
- g.DrawLine(new Pen(BackColor, 2), x, y, x + len, y - len / 2 - 4);
- g.DrawLine(new Pen(BackColor, 2), x, y, x + len, y + len / 2 + 4);
+ g.DrawLine(pen, x, y, x + len, y - len / 2 - 4);
+ g.DrawLine(pen, x, y, x + len, y + len / 2 + 4);
g.SetDefaultQuality();
- g.DrawLine(new Pen(BackColor, 2), x, y, x, y - 60);
- g.DrawLine(new Pen(BackColor, 2), x, y, x, y + 60);
+ g.DrawLine(pen, x, y, x, y - 60);
+ g.DrawLine(pen, x, y, x, y + 60);
//S
DrawVerticalLine(g, ForeColor, 88, 22, 6, 17, true);
diff --git a/SunnyUI/Controls/UIPipe.cs b/SunnyUI/Controls/UIPipe.cs
index 61ac08cb..ae3c8f7c 100644
--- a/SunnyUI/Controls/UIPipe.cs
+++ b/SunnyUI/Controls/UIPipe.cs
@@ -343,7 +343,8 @@ namespace Sunny.UI
{
for (int i = 1; i < w; i++)
{
- g.DrawArc(new Pen(colors[i], 2), new Rectangle(i, i, Width - i * 2, Width - i * 2), 180, 90);
+ using Pen pen = new Pen(colors[i], 2);
+ g.DrawArc(pen, new Rectangle(i, i, Width - i * 2, Width - i * 2), 180, 90);
}
for (int i = 0; i < w; i++)
@@ -362,7 +363,8 @@ namespace Sunny.UI
{
for (int i = 1; i < w; i++)
{
- g.DrawArc(new Pen(colors[i], 2), new Rectangle(i - 1, i, Width - i * 2, Width - i * 2), 270, 90);
+ using Pen pen = new Pen(colors[i], 2);
+ g.DrawArc(pen, new Rectangle(i - 1, i, Width - i * 2, Width - i * 2), 270, 90);
}
for (int i = 0; i < w; i++)
@@ -385,7 +387,8 @@ namespace Sunny.UI
{
for (int i = 1; i < w; i++)
{
- g.DrawArc(new Pen(colors[i], 2), new Rectangle(i, Height - Width + i - 1, Width - i * 2, Width - i * 2), 90, 90);
+ using Pen pen = new Pen(colors[i], 2);
+ g.DrawArc(pen, new Rectangle(i, Height - Width + i - 1, Width - i * 2, Width - i * 2), 90, 90);
}
for (int i = 0; i < w; i++)
@@ -404,7 +407,8 @@ namespace Sunny.UI
{
for (int i = 1; i < w; i++)
{
- g.DrawArc(new Pen(colors[i], 2), new Rectangle(i - 1, Height - Width - 1 + i, Width - i * 2, Width - i * 2), 0, 90);
+ using Pen pen = new Pen(colors[i], 2);
+ g.DrawArc(pen, new Rectangle(i - 1, Height - Width - 1 + i, Width - i * 2, Width - i * 2), 0, 90);
}
for (int i = 0; i < w; i++)
diff --git a/SunnyUI/Controls/UIVerificationCode.cs b/SunnyUI/Controls/UIVerificationCode.cs
index 342582d3..d635c5d7 100644
--- a/SunnyUI/Controls/UIVerificationCode.cs
+++ b/SunnyUI/Controls/UIVerificationCode.cs
@@ -158,7 +158,8 @@ namespace Sunny.UI
// 将位图背景填充为白色
Graphics graph = Graphics.FromImage(destBmp);
- graph.FillRectangle(new SolidBrush(fillColor), 0, 0, destBmp.Width, destBmp.Height);
+ using SolidBrush br = new SolidBrush(fillColor);
+ graph.FillRectangle(br, 0, 0, destBmp.Width, destBmp.Height);
graph.Dispose();
double dBaseAxisLen = bXDir ? (double)destBmp.Height : (double)destBmp.Width;
for (int i = 0; i < destBmp.Width; i++)
diff --git a/SunnyUI/Forms/UIForm.cs b/SunnyUI/Forms/UIForm.cs
index 184199d8..8d182ab9 100644
--- a/SunnyUI/Forms/UIForm.cs
+++ b/SunnyUI/Forms/UIForm.cs
@@ -127,7 +127,7 @@ namespace Sunny.UI
{
this.SetDPIScaleFont();
- if (!UIDPIScale.DPIScaleIsOne())
+ if (UIDPIScale.NeedSetDPIFont())
{
TitleFont = TitleFont.DPIScaleFont();
}
diff --git a/SunnyUI/Frames/UIPage.cs b/SunnyUI/Frames/UIPage.cs
index b0e891bf..8cb72e27 100644
--- a/SunnyUI/Frames/UIPage.cs
+++ b/SunnyUI/Frames/UIPage.cs
@@ -275,7 +275,7 @@ namespace Sunny.UI
if (!IsScaled)
{
this.SetDPIScaleFont();
- if (!UIDPIScale.DPIScaleIsOne())
+ if (UIDPIScale.NeedSetDPIFont())
{
this.TitleFont = TitleFont.DPIScaleFont();
}
diff --git a/SunnyUI/Style/UIDPIScale.cs b/SunnyUI/Style/UIDPIScale.cs
index fe3cb83b..8ce3233c 100644
--- a/SunnyUI/Style/UIDPIScale.cs
+++ b/SunnyUI/Style/UIDPIScale.cs
@@ -38,13 +38,14 @@ namespace Sunny.UI
using Bitmap bmp = new Bitmap(1, 1);
using Graphics g = bmp.Graphics();
- dpiScale = g.DpiX / 96.0f / (UIStyles.FontSize / 12.0f);
+ dpiScale = g.DpiX / 96.0f;
+ if (UIStyles.GlobalFont) dpiScale = dpiScale / (UIStyles.FontScale / 100.0f);
return dpiScale;
}
- public static bool DPIScaleIsOne()
+ public static bool NeedSetDPIFont()
{
- return DPIScale().EqualsFloat(1);
+ return DPIScale() > 1 || UIStyles.GlobalFont;
}
internal static float DPIScaleFontSize(this Font font)
@@ -64,10 +65,20 @@ namespace Sunny.UI
{
if (UIStyles.DPIScale)
{
- if (font.GdiCharSet == 134)
- return new Font(font.FontFamily, fontSize / DPIScale(), font.Style, font.Unit, font.GdiCharSet);
+ if (UIStyles.GlobalFont)
+ {
+ if (font.GdiCharSet == 134)
+ return new Font(UIStyles.FontName, fontSize / DPIScale(), font.Style, font.Unit, font.GdiCharSet);
+ else
+ return new Font(UIStyles.FontName, fontSize / DPIScale());
+ }
else
- return new Font(font.FontFamily, fontSize / DPIScale());
+ {
+ if (font.GdiCharSet == 134)
+ return new Font(font.FontFamily, fontSize / DPIScale(), font.Style, font.Unit, font.GdiCharSet);
+ else
+ return new Font(font.FontFamily, fontSize / DPIScale());
+ }
}
else
{
@@ -81,7 +92,7 @@ namespace Sunny.UI
internal static void SetDPIScaleFont(this Control control)
{
if (!UIStyles.DPIScale) return;
- if (!UIDPIScale.DPIScaleIsOne())
+ if (UIDPIScale.NeedSetDPIFont())
{
if (control is IStyleInterface ctrl)
{
diff --git a/SunnyUI/Style/UIStyleManager.cs b/SunnyUI/Style/UIStyleManager.cs
index 0036d3e8..9e560f82 100644
--- a/SunnyUI/Style/UIStyleManager.cs
+++ b/SunnyUI/Style/UIStyleManager.cs
@@ -79,22 +79,32 @@ namespace Sunny.UI
set => UIStyles.DPIScale = value;
}
- [DefaultValue(12f), Description("DPI缩放开启后,可调字体大小,默认12"), Category("SunnyUI")]
- public float FontSize
- {
- get => UIStyles.FontSize;
- set => UIStyles.FontSize = value;
- }
-
[Editor("System.Drawing.Design.FontNameEditor", "System.Drawing.Design.UITypeEditor")]
[TypeConverter(typeof(FontNameConverter))]
[DefaultValue("微软雅黑")]
- public string FontName
+ [Description("全局字体设置开启后,可调字体名称"), Category("SunnyUI")]
+ public string GlobalFontName
{
get => UIStyles.FontName;
set => UIStyles.FontName = value;
}
+ [DefaultValue(100)]
+ [Description("全局字体设置开启后,可调字体大小缩放百分比,默认100%"), Category("SunnyUI")]
+ public int GlobalFontScale
+ {
+ get => UIStyles.FontScale;
+ set => UIStyles.FontScale = value;
+ }
+
+ [DefaultValue(false)]
+ [Description("全局字体设置"), Category("SunnyUI")]
+ public bool GlobalFont
+ {
+ get => UIStyles.GlobalFont;
+ set => UIStyles.GlobalFont = value;
+ }
+
///
/// 版本
///
diff --git a/SunnyUI/Style/UIStyles.cs b/SunnyUI/Style/UIStyles.cs
index 8b57b0c8..b4aa6593 100644
--- a/SunnyUI/Style/UIStyles.cs
+++ b/SunnyUI/Style/UIStyles.cs
@@ -39,15 +39,17 @@ namespace Sunny.UI
///
public static class UIStyles
{
+ public static bool GlobalFont { get; set; } = false;
+
public static bool DPIScale { get; set; }
public static bool ZoomScale { get; set; }
[Editor("System.Drawing.Design.FontNameEditor", "System.Drawing.Design.UITypeEditor")]
[TypeConverter(typeof(FontNameConverter))]
- public static string FontName { get; set; } = "微软雅黑";
+ internal static string FontName { get; set; } = "微软雅黑";
- public static float FontSize { get; set; } = 12;
+ internal static int FontScale { get; set; } = 100;
private static readonly ConcurrentDictionary FontCharSets = new ConcurrentDictionary();
@@ -403,13 +405,13 @@ namespace Sunny.UI
foreach (var form in Forms.Values)
{
- if (!UIDPIScale.DPIScaleIsOne())
+ if (UIDPIScale.NeedSetDPIFont())
form.SetDPIScale();
}
foreach (var page in Pages.Values)
{
- if (!UIDPIScale.DPIScaleIsOne())
+ if (UIDPIScale.NeedSetDPIFont())
page.SetDPIScale();
}
}