欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

C#常用GDI+文字操作汇总

程序员文章站 2023-12-17 12:09:10
本文实例汇总了c#常用gdi+文字操作,包含了文字的投影、倒影、旋转等常见的效果,在进行c#应用程序开发中有不错的实用价值。分享给大家供大家参考之用。具体如下: 一、投影...

本文实例汇总了c#常用gdi+文字操作,包含了文字的投影、倒影、旋转等常见的效果,在进行c#应用程序开发中有不错的实用价值。分享给大家供大家参考之用。具体如下:

一、投影文字

private void form1_paint(object sender, painteventargs e)
{
  //投影文字
  graphics g = this.creategraphics();
  //设置文本输出质量
  g.textrenderinghint = textrenderinghint.cleartypegridfit;
  g.smoothingmode = smoothingmode.antialias;
  font newfont = new font("times new roman", 48);
  matrix matrix = new matrix();
  //投射
  matrix.shear(-1.5f, 0.0f);
  //缩放
  matrix.scale(1, 0.5f);
  //平移
  matrix.translate(130, 88);
  //对绘图平面实施坐标变换、、
  g.transform = matrix;
  solidbrush graybrush = new solidbrush(color.gray);
  solidbrush colorbrush = new solidbrush(color.blueviolet);
  string text = "mingrisoft";
  //绘制阴影
  g.drawstring(text, newfont, graybrush, new pointf(0, 30));
  g.resettransform();
  //绘制前景
  g.drawstring(text, newfont, colorbrush, new pointf(0, 30));
}

二、倒影文字

private void form1_paint(object sender, painteventargs e)
{
  //倒影文字
  brush backbrush = brushes.gray;
  brush forebrush = brushes.black;
  font font = new font("幼圆", convert.toint16(40), fontstyle.regular);
  graphics g = this.creategraphics();
  string text = "mingrisoft";
  sizef size = g.measurestring(text, font);
  int posx = (this.width - convert.toint16(size.width)) / 2;
  int posy = (this.height - convert.toint16(size.height)) / 2;
  g.translatetransform(posx, posy);
  int ascent = font.fontfamily.getcellascent(font.style);
  int spacing = font.fontfamily.getlinespacing(font.style);
  int lineheight = system.convert.toint16(font.getheight(g));
  int height = lineheight * ascent / spacing;
  graphicsstate state = g.save();
  g.scaletransform(1, -1.0f);
  g.drawstring(text, font, backbrush, 0, -height);
  g.restore(state);
  g.drawstring(text, font, forebrush, 0, -height);
}

三、文字填充线条

private void form1_paint(object sender, painteventargs e)
{
  //使用图像填充文字线条
  texturebrush brush = new texturebrush(image.fromfile(application.startuppath + "\\花.jpg"));
  graphics g = e.graphics;
  g.drawstring("mingrisoft", new font("隶书", 60), brush, new pointf(0, 0)); 
}

四、旋转文字

private void form1_paint(object sender, painteventargs e)
{
  //旋转显示文字
  graphics g = e.graphics;
  g.smoothingmode = system.drawing.drawing2d.smoothingmode.antialias;
  for (int i = 0; i <= 360; i += 10)
  {  
 //平移graphics对象到窗体中心
 g.translatetransform(this.width / 2, this.height / 2);
 //设置graphics对象的输出角度
 g.rotatetransform(i);
 //设置文字填充颜色
 brush brush = brushes.darkviolet;
 //旋转显示文字
 g.drawstring("......mingrisoft", new font("lucida console", 11f), brush, 0, 0);
 //恢复全局变换矩阵
 g.resettransform();
  }
}

五、印版文字

private void form1_paint(object sender, painteventargs e)
{
  //印版文字
  int i = 0;
  brush backbrush = brushes.black;
  brush forebrush = brushes.violet;
  font font = new font("times new roman", system.convert.toint16(40), fontstyle.regular);
  graphics g = this.creategraphics();
  g.clear(color.white);
  string text = "mingrisoft";
  sizef size = g.measurestring(text, font);
  single posx = (this.width - convert.toint16(size.width)) / 2;
  single posy = (this.height - convert.toint16(size.height)) / 3;
  while (i < convert.toint16(20))
  {
 g.drawstring(text, font, backbrush, posx - i, posy + i);
 i = i + 1;
  }
  g.drawstring(text, font, forebrush, posx, posy);
}

相信本文所述实例对大家的c#程序设计有一定的帮助。

上一篇:

下一篇: