使用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);
        }

解决方案 »

  1.   

    //取得点p1围绕点p2顺时针旋转a度后的位置
    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)); }
      

  2.   

    楼上说的是,如果使Graphics旋转,则旋转前要保存它的状态,旋转后再还原回来
      

  3.   

    但是,使用Graphics旋转和其它变换,是最方便的