当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > C#中关于GDI+输出的问题

ASP.NET
asp.net服务器上几种常见异常的解决方案.
Asp.net 下载功能的解决方案
asp.net 页面传值的几个方法
asp.net Cookie跨域、虚拟目录等设置方法
aspnet_isapi.dll设置图文方法.net程序实现伪静态
ASP.NET Web应用程序的安全解决方案浅析
asp.net 图片的读写入库实现代码
asp.net cookie的读写实例
浅析ASP.NET生成随机密码函数
asp.net 防止用户通过后退按钮重复提交表单
ASP.NET 调用百度搜索引擎的代码
asp.net用url重写URLReWriter实现任意二级域名 新
asp.net用url重写URLReWriter实现任意二级域名 高级篇
asp.net 下载文件时根据MIME类型自动判断保存文件的扩展名
asp.net 文件上传 实时进度
asp.net+jquery Gridview的多行拖放, 以及跨控件拖放
ASP.NET 页面之间传递值方式优缺点比较
asp.net 页面转向 Response.Redirect, Server.Transfer, Server.Execute的区别
ASP.NET 返回随机数实现代码
asp.net FreeTextBox配置详解

ASP.NET 中的 C#中关于GDI+输出的问题


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 85 ::
收藏到网摘: n/a

在.net Framework的框架中有很多操作各种图形的函数,包括:点,线,面等等,构成的各种各样的丰富的图象。
在这里我主要是介绍在.Net Framework中GDI+下的TEXT(文本)的操作。首先以一个小小的程序开始:
建立一个Windows应用程序
在窗体上添加一个Button控件 和 一个PictureBox控件.
在Button控件的事件中添加,如下代码:
SizeF textSize ;//定义一个SizeF的变量,而SizeF的描述:
//存储有序浮点数对,通常为矩形的宽度和高度。
Graphics g;
Brush myBrush ;//定义一个刷子。
Font myFont = new Font("Times new Roman", 80, FontStyle.Bold);
//定义要输出字体的样式和大小
g = pictureBox1.CreateGraphics();//CreateGraphics 方法
也可以使用某控件或窗体的 CreateGraphics 方法来获取对 Graphics 对象的引用,该对象表示该控件或窗体的绘图表面
g.Clear(Color.White);// 清除整个绘图面并以指定背景色填充。
string str = "Kevin";//要输出的文本
textSize = g.MeasureString(str,myFont);// 测量用指定的 Font 对象绘制的指定字符串。
myBrush=new HatchBrush(HatchStyle.DashedUpwardDiagonal,Color.Blue,Color.White);
//这里使用的是HatchBrush画刷。
g.DrawString(str,myFont,myBrush,(pictureBox1.Width/4),(pictureBox1.Height/2));

//输出文本


当然如果将上述代码在变一下的话。就是另外一番风景啊~~

SizeF textSize ;
Graphics g;
Brush myBrush;
Single xLocation,yLocation;
Matrix myMatrix;
Font myFont = new Font("Times new Roman", 80, FontStyle.Bold);
g = pictureBox1.CreateGraphics();
g.Clear(Color.White);
string str = "Kevin";
textSize = g.MeasureString(str,myFont);
xLocation = (pictureBox1.Width/4)-5;
yLocation =(pictureBox1.Height/2-5);
g.TranslateTransform(xLocation,yLocation);
myMatrix = g.Transform;
myMatrix.Shear(1,0);
g.Transform = myMatrix;
myBrush=new HatchBrush(HatchStyle.DashedUpwardDiagonal,Color.Blue,Color.White);
g.DrawString(str,myFont,myBrush,0,0);


SizeF textSize ;
Graphics g;
Brush myBrush = Brushes.Blue;
Brush backBrush= Brushes.Gray;
Single xLocation,yLocation;
Font myFont = new Font("Times new Roman", 80, FontStyle.Bold);
g = pictureBox1.CreateGraphics();
g.Clear(Color.White);
string str = "Kevin";
textSize = g.MeasureString(str,myFont);
xLocation = (pictureBox1.Width/4)-5;
yLocation =(pictureBox1.Height/2-5);
g.DrawString(str,myFont,backBrush,(pictureBox1.Width/4),(pictureBox1.Height/2));
g.DrawString(str,myFont,myBrush,xLocation,yLocation);


这就是我想给各位的一个非常简单的操作文本程序。