要使用GDI+,必须先创建Graphics对象,创建Graphics共有三种方法,第一种为

private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
   Graphics g =e.Graphics;

第二种为:Graphics gh = this.CreateGraphics();也可以用Graphics gh = Button1.CreateGraphics;

第三种为:

Bitmap myBitmap=new Bitmap("C:/myPic.bmp");

Graphics  g= Graphics.FromImage(myBitmap);

 

//使用Graphics 

g.SmoothingMode=SmoothingMode.Default;

string tempstr = "章松山";
SizeF f = g.MeasureString(tempstr, new Font("宋体", 9));

g.TranslateTransform(f.Height,0);//偏移量
g.RotateTransform(45);

Brush myBrush = Brushes.Blue;
g.DrawString(tempstr, this.Font, myBrush, 0, 0);
g.DrawRectangle(new Pen(Color.Red), 0, 0, f.Width, f.Height);
g.ResetTransform();

 

//以上绘制了一个带方框的文本。