本文整理汇总了C#中System.Drawing.Drawing2D.LinearGradientBrush.SafeDispose方法的典型用法代码示例。如果您正苦于以下问题:C# LinearGradientBrush.SafeDispose方法的具体用法?C# LinearGradientBrush.SafeDispose怎么用?C# LinearGradientBrush.SafeDispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Drawing2D.LinearGradientBrush
的用法示例。
在下文中一共展示了LinearGradientBrush.SafeDispose方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DrawBackground
private void DrawBackground(Graphics graphics)
{
//
// Create gradient brush
//
Brush gradientBrush = new LinearGradientBrush(workingLabel.ClientRectangle,
firstColor,
lastColor,
LinearGradientMode.Horizontal);
//
// Draw brush
//
graphics.FillRectangle(gradientBrush, this.ClientRectangle);
gradientBrush.SafeDispose();
}
示例2: DrawFadingText
private void DrawFadingText(Graphics g, SizeF stringSize, string text, Rectangle rect, Font font, Color color)
{
LinearGradientBrush fadingBrush = null;
try
{
fadingBrush = new LinearGradientBrush(rect, Color.FromArgb(255, color), Color.FromArgb(128, color),
LinearGradientMode.Horizontal);
Blend fadeBlend = new Blend(4);
fadeBlend.Factors = new float[] {0, 0, .85f, 1};
float fadeStart = Math.Max(1, rect.Width - 50) / (float)rect.Width;
float fadeMiddle = Math.Max(1, rect.Width - 15) / (float)rect.Width;
float fadeEnd = 1;
fadeBlend.Positions = new float[] {0, fadeStart, fadeMiddle, fadeEnd};
fadingBrush.Blend = fadeBlend;
g.DrawString(text, font, fadingBrush, rect, TextStringFormat);
}
finally
{
if (fadingBrush != null)
{
fadingBrush.SafeDispose();
fadingBrush = null;
}
}
}