Dispose GetWindowsFont return value (#3482)

This commit is contained in:
gpetrou 2020-06-23 09:31:52 +01:00 коммит произвёл GitHub
Родитель b22a5ace3f
Коммит c231d486a0
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 22 добавлений и 27 удалений

Просмотреть файл

@ -538,18 +538,16 @@ namespace System.Windows.Forms
flags |= User32.DT.RIGHT;
}
using (WindowsFont wfont = WindowsGraphicsCacheManager.GetWindowsFont(Font))
{
textSize = wg.MeasureText(Text, wfont, new Size(textRectangle.Width, int.MaxValue), flags);
using WindowsFont wfont = WindowsGraphicsCacheManager.GetWindowsFont(Font);
textSize = wg.MeasureText(Text, wfont, new Size(textRectangle.Width, int.MaxValue), flags);
if (Enabled)
{
wg.DrawText(Text, wfont, textRectangle, ForeColor, flags);
}
else
{
ControlPaint.DrawStringDisabled(wg, Text, Font, backColor, textRectangle, ((TextFormatFlags)flags));
}
if (Enabled)
{
wg.DrawText(Text, wfont, textRectangle, ForeColor, flags);
}
else
{
ControlPaint.DrawStringDisabled(wg, Text, Font, backColor, textRectangle, (TextFormatFlags)flags);
}
}
}

Просмотреть файл

@ -1275,13 +1275,11 @@ namespace System.Windows.Forms
wg.TextPadding = TextPaddingOptions.LeftAndRightPadding;
}
using (WindowsFont wf = WindowsGraphicsCacheManager.GetWindowsFont(Font))
{
User32.DRAWTEXTPARAMS dtParams = wg.GetTextMargins(wf);
using WindowsFont wf = WindowsGraphicsCacheManager.GetWindowsFont(Font);
User32.DRAWTEXTPARAMS dtParams = wg.GetTextMargins(wf);
// This is actually leading margin.
return dtParams.iLeftMargin;
}
// This is actually leading margin.
return dtParams.iLeftMargin;
}
}

Просмотреть файл

@ -703,12 +703,10 @@ namespace System.Windows.Forms
wg.TextPadding = TextPaddingOptions.LeftAndRightPadding;
}
using (WindowsFont wf = WindowsGraphicsCacheManager.GetWindowsFont(Font))
{
User32.DRAWTEXTPARAMS dtParams = wg.GetTextMargins(wf);
iLeftMargin = dtParams.iLeftMargin;
iRightMargin = dtParams.iRightMargin;
}
using WindowsFont wf = WindowsGraphicsCacheManager.GetWindowsFont(Font);
User32.DRAWTEXTPARAMS dtParams = wg.GetTextMargins(wf);
iLeftMargin = dtParams.iLeftMargin;
iRightMargin = dtParams.iRightMargin;
}
Rectangle visualRectangle = new Rectangle(clientRectWithPadding.X + iLeftMargin,

Просмотреть файл

@ -181,7 +181,7 @@ namespace System.Windows.Forms
return Size.Empty;
}
WindowsFont? wf = WindowsGraphicsCacheManager.GetWindowsFont(font);
using WindowsFont? wf = WindowsGraphicsCacheManager.GetWindowsFont(font);
return WindowsGraphicsCacheManager.MeasurementGraphics.MeasureText(text, wf);
}
@ -192,8 +192,8 @@ namespace System.Windows.Forms
return Size.Empty;
}
WindowsFont? wf = WindowsGraphicsCacheManager.GetWindowsFont(font);
return WindowsGraphicsCacheManager.MeasurementGraphics.MeasureText(text, WindowsGraphicsCacheManager.GetWindowsFont(font), proposedSize);
using WindowsFont? wf = WindowsGraphicsCacheManager.GetWindowsFont(font);
return WindowsGraphicsCacheManager.MeasurementGraphics.MeasureText(text, wf, proposedSize);
}
public static Size MeasureText(string? text, Font? font, Size proposedSize, TextFormatFlags flags)
@ -202,7 +202,8 @@ namespace System.Windows.Forms
{
return Size.Empty;
}
WindowsFont? wf = WindowsGraphicsCacheManager.GetWindowsFont(font);
using WindowsFont? wf = WindowsGraphicsCacheManager.GetWindowsFont(font);
return WindowsGraphicsCacheManager.MeasurementGraphics.MeasureText(text, wf, proposedSize, GetTextFormatFlags(flags));
}