除了图像之外,如果要针对文字做出绘图变化,则 .Net Framework System.Drawing 命名空间中的 Graphics  Brush 类别将最是简便的。接下来,,我们将介绍如何运用笔刷来产生带有花纹与渐层效果的文字。 

 

程序范例 

Visual C# 2005 - 如何利用程序代码产生多变化字体之笔刷字
图表1 

Visual C# 2005 - 如何利用程序代码产生多变化字体之笔刷字
图表2 

 

我们撰写了一个程序范例,示范如何利用 Graphics 类别的 DrawString 方法来产生带有花纹与渐层效果的文字,执行结果如图表 1  2 所示,程序代码如下所示: 

SizeF textSize;
Graphics g;
Brush myBrush;
RectangleF gradientRectangle;
Font myFont = new Font("Times New Roman",
  (float)this.nudFontSize.Value, FontStyle.Regular);

g = picDemoArea.CreateGraphics();
g.Clear(Color.White);

textSize = g.MeasureString(this.txtShortText.Text, myFont);

if(this.optHatch.Checked)
{
 myBrush = new HatchBrush(HatchStyle.DiagonalBrick, Color.Blue,
   Color.Yellow);
}
else
{
gradientRectangle = new RectangleF(new PointF(0, 0), textSize);
myBrush = new LinearGradientBrush(gradientRectangle,
  Color.Blue,
  Color.Yellow, LinearGradientMode.ForwardDiagonal);
}

g.DrawString(txtShortText.Text, myFont, myBrush,
  (picDemoArea.Width - textSize.Width) / 2,
  (picDemoArea.Height - textSize.Height) / 2);

相关文章:

  • 2021-10-03
  • 2021-11-17
  • 2022-03-06
  • 2021-11-14
  • 2021-12-06
  • 2021-11-18
  • 2022-12-23
  • 2022-02-08
猜你喜欢
  • 2022-03-01
  • 2021-05-22
  • 2021-12-16
  • 2021-08-01
  • 2021-08-30
  • 2022-12-23
  • 2021-10-16
相关资源
相似解决方案