Net Framework  System.Drawing 命名空间中的 Graphics  Brush类别可以让我们轻易对文字做出绘图变化。在此,我们将示范如何运用笔刷来产生带有阴影效果的文字。 

 

程序范例 

Visual C# 2005 - 如何制作多变化字体之阴影字
图表1

Visual C# 2005 - 如何制作多变化字体之阴影字
图表2 

 

我们所撰写的程序范例示范如何利用 Graphics 类别的 DrawString 方法,来根据用户所选取的设定绘制出带有阴影效果的文字。程序执行结果如图表 1 2 所示,相关程序代码列示如下: 

 

SizeF textSize;
Graphics g;
Brush myShadowBrush = Brushes.Gray;
Brush myForeBrush = Brushes.Blue;
Font myFont = new Font("Times New Roman",
  (float)this.nudFontSize.Value, FontStyle.Regular);
float xLocation, yLocation;

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

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

xLocation = (picDemoArea.Width - textSize.Width) / 2;
yLocation = (picDemoArea.Height - textSize.Height) / 2;

g.DrawString(txtShortText.Text, myFont, myShadowBrush,
  xLocation + (float)this.nudShadowDepth.Value,
  yLocation + (float)this.nudShadowDepth.Value);

g.DrawString(txtShortText.Text, myFont, myForeBrush, xLocation,
  yLocation);

相关文章:

  • 2021-07-29
  • 2022-12-23
  • 2021-11-22
  • 2021-12-30
  • 2022-12-23
  • 2021-12-02
  • 2021-09-12
  • 2021-10-06
猜你喜欢
  • 2022-03-01
  • 2021-05-22
  • 2021-11-11
  • 2022-12-23
  • 2022-12-23
  • 2022-01-15
  • 2021-06-28
相关资源
相似解决方案