Region.Transform(Matrix) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
public:
void Transform(System::Drawing::Drawing2D::Matrix ^ matrix);
public void Transform (System.Drawing.Drawing2D.Matrix matrix);
member this.Transform : System.Drawing.Drawing2D.Matrix -> unit
Public Sub Transform (matrix As Matrix)
參數
例外狀況
matrix
null
。
範例
下列程式代碼範例是專為搭配 Windows Forms 使用而設計,而且需要 PaintEventArgse
,這是 Paint 事件處理程式的參數。 程式代碼會執行下列動作:
建立矩形,並以藍色將它繪製到螢幕。
從矩形建立區域。
建立轉換矩陣,並將其設定為45度。
將轉換套用至區域。
以紅色填滿轉換的區域,並以紅色將轉換的區域繪製到畫面。
請注意,紅色矩形會從原始矩形旋轉 45 度,以藍色顯示。
public:
void TransformExample( PaintEventArgs^ e )
{
// Create the first rectangle and draw it to the screen in blue.
Rectangle regionRect = Rectangle(100,50,100,100);
e->Graphics->DrawRectangle( Pens::Blue, regionRect );
// Create a region using the first rectangle.
System::Drawing::Region^ myRegion = gcnew System::Drawing::Region( regionRect );
// Create a transform matrix and set it to have a 45 degree
// rotation.
Matrix^ transformMatrix = gcnew Matrix;
transformMatrix->RotateAt( 45, Point(100,50) );
// Apply the transform to the region.
myRegion->Transform(transformMatrix);
// Fill the transformed region with red and draw it to the screen
// in red.
SolidBrush^ myBrush = gcnew SolidBrush( Color::Red );
e->Graphics->FillRegion( myBrush, myRegion );
}
public void TransformExample(PaintEventArgs e)
{
// Create the first rectangle and draw it to the screen in blue.
Rectangle regionRect = new Rectangle(100, 50, 100, 100);
e.Graphics.DrawRectangle(Pens.Blue, regionRect);
// Create a region using the first rectangle.
Region myRegion = new Region(regionRect);
// Create a transform matrix and set it to have a 45 degree
// rotation.
Matrix transformMatrix = new Matrix();
transformMatrix.RotateAt(45, new Point(100, 50));
// Apply the transform to the region.
myRegion.Transform(transformMatrix);
// Fill the transformed region with red and draw it to the screen
// in red.
SolidBrush myBrush = new SolidBrush(Color.Red);
e.Graphics.FillRegion(myBrush, myRegion);
}
Public Sub TransformExample(ByVal e As PaintEventArgs)
' Create the first rectangle and draw it to the screen in blue.
Dim regionRect As New Rectangle(100, 50, 100, 100)
e.Graphics.DrawRectangle(Pens.Blue, regionRect)
' Create a region using the first rectangle.
Dim myRegion As New [Region](regionRect)
' Create a transform matrix and set it to have a 45 degree
' rotation.
Dim transformMatrix As New Matrix
transformMatrix.RotateAt(45, New PointF(100, 50))
' Apply the transform to the region.
myRegion.Transform(transformMatrix)
' Fill the transformed region with red and draw it to the
' screen in red.
Dim myBrush As New SolidBrush(Color.Red)
e.Graphics.FillRegion(myBrush, myRegion)
End Sub