* 重构一些笔刷和画笔的资源释放

This commit is contained in:
Sunny 2023-05-28 21:10:04 +08:00
parent 50fe88ee07
commit bcbab4f4eb
4 changed files with 33 additions and 26 deletions

View File

@ -226,7 +226,7 @@ namespace Sunny.UI
protected void DrawSelector(Graphics dc, RectangleF r, Orientation orientation, float percentSet) protected void DrawSelector(Graphics dc, RectangleF r, Orientation orientation, float percentSet)
{ {
Pen pen = new Pen(Color.CadetBlue); using Pen pen = new Pen(Color.CadetBlue);
percentSet = Math.Max(0, percentSet); percentSet = Math.Max(0, percentSet);
percentSet = Math.Min(1, percentSet); percentSet = Math.Min(1, percentSet);
if (orientation == Orientation.Vertical) if (orientation == Orientation.Vertical)

View File

@ -20,6 +20,12 @@ namespace Sunny.UI
private readonly List<Color> m_colors = new List<Color>(); private readonly List<Color> m_colors = new List<Color>();
private double m_wheelLightness = 0.5; private double m_wheelLightness = 0.5;
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
m_brush?.Dispose();
}
public HSLColor SelectedHSLColor public HSLColor SelectedHSLColor
{ {
get { return m_selectedColor; } get { return m_selectedColor; }

View File

@ -623,7 +623,7 @@ namespace Sunny.UI
// Set antialias effect on // Set antialias effect on
gOffScreen.SmoothingMode = SmoothingMode.AntiAlias; gOffScreen.SmoothingMode = SmoothingMode.AntiAlias;
// Draw border of knob // Draw border of knob
gOffScreen.DrawEllipse(new Pen(this.BackColor), rKnob); gOffScreen.DrawEllipse(this.BackColor, rKnob);
//if control is focused //if control is focused
if (this.isFocused) if (this.isFocused)
@ -846,7 +846,8 @@ namespace Sunny.UI
int w = l / 4; int w = l / 4;
Point[] pt = GetKnobLine(Gr, l); Point[] pt = GetKnobLine(Gr, l);
Gr.DrawLine(new Pen(_PointerColor, w), pt[0], pt[1]); using Pen pen = new Pen(_PointerColor, w);
Gr.DrawLine(pen, pt[0], pt[1]);
} }
else else
{ {
@ -891,8 +892,8 @@ namespace Sunny.UI
Rectangle rPointer = new Rectangle(Arrow.X - w / 2, Arrow.Y - w / 2, w, h); Rectangle rPointer = new Rectangle(Arrow.X - w / 2, Arrow.Y - w / 2, w, h);
//Utility.DrawInsetCircle(ref Gr, rPointer, new Pen(_PointerColor)); //Utility.DrawInsetCircle(ref Gr, rPointer, new Pen(_PointerColor));
DrawInsetCircle(ref Gr, rPointer, new Pen(GetLightColor(_PointerColor, 55))); using Pen pen = new Pen(GetLightColor(_PointerColor, 55));
DrawInsetCircle(ref Gr, rPointer, pen);
Gr.FillEllipse(brushKnobPointer, rPointer); Gr.FillEllipse(brushKnobPointer, rPointer);
} }
} }
@ -1467,8 +1468,8 @@ namespace Sunny.UI
} }
public static void DrawInsetCircle(ref Graphics g, Rectangle r, Pen p) public static void DrawInsetCircle(ref Graphics g, Rectangle r, Pen p)
{ {
Pen p1 = new Pen(GetDarkColor(p.Color, 50)); using Pen p1 = new Pen(GetDarkColor(p.Color, 50));
Pen p2 = new Pen(GetLightColor(p.Color, 50)); using Pen p2 = new Pen(GetLightColor(p.Color, 50));
for (int i = 0; i < p.Width; i++) for (int i = 0; i < p.Width; i++)
{ {
Rectangle r1 = new Rectangle(r.X + i, r.Y + i, r.Width - i * 2, r.Height - i * 2); Rectangle r1 = new Rectangle(r.X + i, r.Y + i, r.Width - i * 2, r.Height - i * 2);

View File

@ -34,6 +34,12 @@ namespace Sunny.UI
[DefaultProperty("Text")] [DefaultProperty("Text")]
public sealed class UISmoothLabel : Label, IStyleInterface, IZoomScale public sealed class UISmoothLabel : Label, IStyleInterface, IZoomScale
{ {
private PointF point;
private SizeF drawSize;
private Pen drawPen;
private GraphicsPath drawPath;
private SolidBrush forecolorBrush;
public UISmoothLabel() public UISmoothLabel()
{ {
base.Font = UIStyles.Font(); base.Font = UIStyles.Font();
@ -43,11 +49,23 @@ namespace Sunny.UI
rectColor = UIStyles.Blue.SmoothLabelRectColor; rectColor = UIStyles.Blue.SmoothLabelRectColor;
drawPath = new GraphicsPath(); drawPath = new GraphicsPath();
drawPen = new Pen(new SolidBrush(rectColor), rectSize); drawPen = new Pen(rectColor, rectSize);
forecolorBrush = new SolidBrush(ForeColor); forecolorBrush = new SolidBrush(ForeColor);
Size = new Size(300, 60); Size = new Size(300, 60);
} }
protected override void Dispose(bool disposing)
{
if (disposing)
{
forecolorBrush?.Dispose();
drawPath?.Dispose();
drawPen?.Dispose();
}
base.Dispose(disposing);
}
/// <summary> /// <summary>
/// 禁止控件跟随窗体缩放 /// 禁止控件跟随窗体缩放
/// </summary> /// </summary>
@ -69,24 +87,6 @@ namespace Sunny.UI
} }
protected override void Dispose(bool disposing)
{
if (disposing)
{
forecolorBrush?.Dispose();
drawPath?.Dispose();
drawPen?.Dispose();
}
base.Dispose(disposing);
}
private PointF point;
private SizeF drawSize;
private Pen drawPen;
private GraphicsPath drawPath;
private SolidBrush forecolorBrush;
[Browsable(false), DefaultValue(false)] [Browsable(false), DefaultValue(false)]
public bool IsScaled { get; set; } public bool IsScaled { get; set; }