您的位置:首页 > 其它

GDI+文字旋转

2009-11-09 14:53 260 查看
要使用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();

//以上绘制了一个带方框的文本。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: