csharp System.Drawing.Rectangleを回転させる方法(旋转矩形)(C#)(WinForms)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp System.Drawing.Rectangleを回転させる方法(旋转矩形)(C#)(WinForms)相关的知识,希望对你有一定的参考价值。

http://stackoverflow.com/questions/10210134/using-a-matrix-to-rotate-rectangles-individually
using System; 
using System.Collections.Generic; 
using System.Drawing; 
using System.Drawing.Drawing2D; 
using System.Linq; 
using System.Windows.Forms; 
 
namespace WindowsFormsApplication1 
{ 
  public partial class Form1 : Form 
  { 
    private Rectangle r1 = new Rectangle(100, 60, 32, 32); 
    private Rectangle r2 = new Rectangle(160, 100, 32, 32); 
 
    Graphics g; 
 
    public Form1() 
    { 
      InitializeComponent(); 
 
      Paint += Form1_Paint; 
 
      FormClosing += (s, e) =>  
        { 
          g.Dispose(); 
        }; 
    } 
 
    public void RotateRectangle(Graphics g, Rectangle r, float angle, Pen pen) 
    { 
      using (Matrix m = new Matrix()) 
      { 
        m.RotateAt(angle, new PointF(r.Left + (r.Width / 2), r.Top + (r.Height / 2))); 
        g.Transform = m; 
        g.DrawRectangle(pen, r); 
        g.ResetTransform(); 
      } 
    }
    
    private void Form1_Paint(object sender, PaintEventArgs e) 
    {  
      g= e.Graphics; 
      g.SmoothingMode = SmoothingMode.HighQuality; 
 
      RotateRectangle(g, r1, 0, Pens.Black); 
      RotateRectangle(g, r1, 65, Pens.Red); 
    } 
  } 
}

以上是关于csharp System.Drawing.Rectangleを回転させる方法(旋转矩形)(C#)(WinForms)的主要内容,如果未能解决你的问题,请参考以下文章

csharp 例如-CSHARP-GroupDocs.Conversion.Examples.CSharp渲染,RenderPSDImageAsPath.cs

csharp 实例-CSHARP-GroupDocs.Conversion.Examples.CSharp变频-ConvertTopresentationAsPath.cs

csharp 实例-CSHARP-GroupDocs.Conversion.Examples.CSharp变频-ConvertTopresentationAsPath.cs

csharp 实例-CSHARP-GroupDocs.Conversion.Examples.CSharp变频-ConvertTopresentationAsPath.cs

csharp 例如-CSHARP-GroupDocs.Search.Examples.CSharp索引,AddDocumentToIndex.cs

csharp 例如-CSHARP-GroupDocs.Search.Examples.CSharp索引,AddDocumentToIndexAsynchronously.cs