Region.Transform(Matrix) 方法
定义
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。matrix is null.
示例
下面的代码示例旨在与 Windows 窗体一起使用,并且它需要作为 PaintEventArgs e Paint 事件处理程序的参数。The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. 此代码执行以下操作:The code performs the following actions:
创建一个矩形,并将其绘制到屏幕蓝色。Creates a rectangle and draws it to the screen in blue.
从矩形创建区域。Creates a region from the rectangle.
创建变换矩阵并将其设置为45度。Creates a transformation matrix and sets it to 45 degrees.
将转换应用于区域。Applies the transformation to the region.
用红色填充变换后的区域,并将变换后的区域绘制为红色。Fills the transformed region with red and draws the transformed region to the screen in red.
请注意,红色矩形从原始矩形旋转了45度,用蓝色显示。Notice that the red rectangle is rotated 45 degrees from the original rectangle, shown in blue.
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