使用Matrix的Rotate方法。 private void Form1_Paint(object sender, PaintEventArgs e)
{
Pen myPen = new Pen(Color.Blue, 1);
Pen myPen2 = new Pen(Color.Red, 1);
// Draw the rectangle to the screen before applying the transform.
e.Graphics.DrawRectangle(myPen, 150, 50, 200, 100);
// Create a matrix and rotate it 45 degrees.
Matrix myMatrix = new Matrix();
myMatrix.Rotate(45, MatrixOrder.Append);
// Draw the rectangle to the screen again after applying the
// transform.
e.Graphics.Transform = myMatrix;
e.Graphics.DrawRectangle(myPen2, 150, 50, 200, 100);
}
{
Pen myPen = new Pen(Color.Blue, 1);
Pen myPen2 = new Pen(Color.Red, 1);
// Draw the rectangle to the screen before applying the transform.
e.Graphics.DrawRectangle(myPen, 150, 50, 200, 100);
// Create a matrix and rotate it 45 degrees.
Matrix myMatrix = new Matrix();
myMatrix.Rotate(45, MatrixOrder.Append);
// Draw the rectangle to the screen again after applying the
// transform.
e.Graphics.Transform = myMatrix;
e.Graphics.DrawRectangle(myPen2, 150, 50, 200, 100);
}
解决方案 »
- C# 将XML读取到DataSet中问题
- 100求解:winform backgroundworker内调用控件,出现线程间操作无效
- 关于二进制文件续写问题
- 窗体逐渐显示
- 如何用C#实现在程序里直接将当前所用的域用户设置为本机管理员
- 有没有什么办法让处于可编辑状态下的网页点回车不以<P>,而已<BR>换行?
- 请教C#中的System.Drawing.Icon类对象怎么存文件名?
- C#从XML文件利用XPAth获取指定属性值,并显示到datagridview
- 如何让百度地图API中的InfoWindow显示内容为已经做好的html网页
- c#获取html内容
- 在VS.Net 2005下怎么访问VFP 数据库阿
- 有关TabControl的问题
private Point PRotate(Point p1,Point p2,double a)
{
double x1=(double)(p1.X-p2.X);
double y1=(double)(p2.Y-p1.Y);
double aa=Math.PI*a/180;
return new Point((int)(y1*Math.Sin(aa)+x1*Math.Cos(aa))+p2.X,p2.Y-(int)(y1*Math.Cos(aa)-x1*Math.Sin(aa)));
}
//画出矩形r1围绕点p旋转a度后的图形
private void DrawRotateRect(Rectangle r1,Point p,double a,Graphics g1,Pen pen)
{
Point p1=PRotate(new Point(r1.X,r1.Y),p,a);
Point p2=PRotate(new Point(r1.X+r1.Width,r1.Y),p,a);
Point p3=PRotate(new Point(r1.X+r1.Width,r1.Y+r1.Height),p,a);
Point p4=PRotate(new Point(r1.X,r1.Y+r1.Height),p,a);
g1.DrawLine(pen,p1,p2);
g1.DrawLine(pen,p2,p3);
g1.DrawLine(pen,p3,p4);
g1.DrawLine(pen,p4,p1);
}
//调用方法
private void panel1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
Rectangle r1=new Rectangle(80,80,30,40);
e.Graphics.DrawRectangle(new Pen(Color.Red),r1);
DrawRotateRect(r1,new Point(80,80),90,e.Graphics,new Pen(Color.Blue)); }