Visual C# 2005 - 如何制作多变化字体之浮雕字

 

本文将示范如何利用 System.Drawing 命名空间中的 Graphics Brush 类别来制作出带有浮雕效果的文字。 

程序范例 

 

图表1 

 

图表2 

图表 1 2 是我们所撰写之程序范例的执行结果。我们主要使用 Graphics 类别的 DrawString 方法,并根据用户所选取的刻度去调整绘图字号,以便制作出带有浮雕效果的文字。程序代码列示如下: 

SizeF textSize;
Graphics g;
Brush myBackBrush = Brushes.Blue;
Brush myForeBrush = Brushes.White;
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, myBackBrush,
  xLocation + (float)this.nudEmbossDepth.Value,
  yLocation + (float)this.nudEmbossDepth.Value);

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


posted on 2006-11-22 09:54 章立民研究室 阅读(2131) 评论(6)  编辑 收藏 所属分类: Visual C# 2005

导航

公告


章立民
六度当选MVP
七十本著作酿成
十九载作者生涯
现在有了章立民研究室
依旧陶醉在写作的生活里。

统计

与我联系

搜索

 

常用链接

留言簿(313)

随笔分类(111)

随笔档案(110)

光盘勘误下载

最新随笔

积分与排名

最新评论

阅读排行榜

评论排行榜