//绘制倾斜文字
方法1:
System.Drawing.Graphics
public Void DrawString(
String s,
Font font, // FontStyle.Italic 就是斜体字
Brush brush,
PointF point)
方法2:
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
// 声明并初始化Graphics对象g
Graphics g = e.Graphics;
g.SmoothingMode = SmoothingMode.AntiAlias;
string tempStr = "Hello,C#";//取得要显示的文字
for(int i=0;i<361;i+=10){
//将指定的平移添加到g的变换矩阵前
g.TranslateTransform(150,150);
// 将指定的旋转用于g的变换矩阵
g.RotateTransform(i);
// 定义自己的画刷
Brush myBrush = Brushes.Blue;
//显示旋转文字
g.DrawString(tempStr,this.Font,myBrush,60,0);
// 将g的全局变换矩阵重置为单位矩阵
g.ResetTransform();
}
//绘制倾斜矩形
方法1:
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Rectangle rect = new Rectangle(100, 10, 100, 60);
e.Graphics.RotateTransform(45, System.Drawing.Drawing2D.MatrixOrder.Append);
e.Graphics.DrawRectangle(SystemPens.ControlDark, rect);
}
方法2:
using System.Drawing.Drawing2D;
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
e.Graphics.DrawRectangle(
Pens.Blue,
200, 100, 100, 60);
Matrix matrix = new Matrix();
matrix.RotateAt(45,new PointF(200,100),MatrixOrder.Append);
e.Graphics.Transform = matrix;
e.Graphics.DrawRectangle(Pens.Red,
200, 100, 100, 60);
}