本文整理匯總了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;
}
}
}