在.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);

這就是我想給各位的一個非常簡單的操作文本程序。
新聞熱點
疑難解答