LinearGradientBrush.TranslateTransform 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
依指定的維度轉譯局部幾何轉換。 這個方法會在轉換前加上轉譯。
多載
TranslateTransform(Single, Single, MatrixOrder) |
依指定的順序,轉譯指定維度的局部幾何轉換。 |
TranslateTransform(Single, Single) |
依指定的維度轉譯局部幾何轉換。 這個方法會在轉換前加上轉譯。 |
TranslateTransform(Single, Single, MatrixOrder)
依指定的順序,轉譯指定維度的局部幾何轉換。
public:
void TranslateTransform(float dx, float dy, System::Drawing::Drawing2D::MatrixOrder order);
public void TranslateTransform (float dx, float dy, System.Drawing.Drawing2D.MatrixOrder order);
member this.TranslateTransform : single * single * System.Drawing.Drawing2D.MatrixOrder -> unit
Public Sub TranslateTransform (dx As Single, dy As Single, order As MatrixOrder)
參數
- dx
- Single
x 中轉譯的值。
- dy
- Single
y 中翻譯的值。
- order
- MatrixOrder
要套用翻譯的順序(前面或附加)。
範例
下列程式代碼範例的設計目的是要與 Windows Forms 搭配使用,而且需要 PaintEventArgse
OnPaint 事件物件。 程式代碼會執行下列動作:
建立新的 LinearGradientBrush。
使用此筆刷將矩形繪製到具有色彩線性、由左至右轉換的螢幕。
將 LinearGradientBrush 旋轉 90 度,並縮放漸層。
使用旋轉和縮放漸層繪製矩形到螢幕。
轉譯矩形,使其具有從上到下執行的線性漸層。
將翻譯的矩形繪製到畫面。
請注意,有三個矩形顯示頂端一個,其中顯示由左至右的漸層、中間一個顯示旋轉和縮放漸層,另一個矩形則顯示最後一個轉譯的漸層。
private:
void TranslateTransformExample( PaintEventArgs^ e )
{
// Create a LinearGradientBrush.
Rectangle myRect = Rectangle(20,20,200,100);
LinearGradientBrush^ myLGBrush = gcnew LinearGradientBrush( myRect,Color::Blue,Color::Red,0.0f,true );
// Draw a rectangle to the screen using the LinearGradientBrush.
e->Graphics->FillRectangle( myLGBrush, myRect );
// Rotate the LinearGradientBrush.
myLGBrush->RotateTransform( 90.0f );
// Scale the gradient for the height of the rectangle.
myLGBrush->ScaleTransform( 0.5f, 1.0f );
// Draw to the screen, the rotated and scaled gradient.
e->Graphics->FillRectangle( myLGBrush, 20, 150, 200, 100 );
// Rejustify the brush to start at the top edge of the
// rectangle.
myLGBrush->TranslateTransform( -20.0f, 0.0f );
// Draw a third rectangle to the screen using the translated
// brush.
e->Graphics->FillRectangle( myLGBrush, 20, 300, 200, 100 );
}
private void TranslateTransformExample(PaintEventArgs e)
{
// Create a LinearGradientBrush.
Rectangle myRect = new Rectangle(20, 20, 200, 100);
LinearGradientBrush myLGBrush = new LinearGradientBrush(
myRect, Color.Blue, Color.Red, 0.0f, true);
// Draw a rectangle to the screen using the LinearGradientBrush.
e.Graphics.FillRectangle(myLGBrush, myRect);
// Rotate the LinearGradientBrush.
myLGBrush.RotateTransform(90.0f);
// Scale the gradient for the height of the rectangle.
myLGBrush.ScaleTransform(0.5f, 1.0f);
// Draw to the screen, the rotated and scaled gradient.
e.Graphics.FillRectangle(myLGBrush, 20, 150, 200, 100);
// Rejustify the brush to start at the top edge of the
// rectangle.
myLGBrush.TranslateTransform(-20.0f, 0.0f);
// Draw a third rectangle to the screen using the translated
// brush.
e.Graphics.FillRectangle(myLGBrush, 20, 300, 200, 100);
}
Public Sub TranslateTransformExample(ByVal e As PaintEventArgs)
' Create a LinearGradientBrush.
Dim myRect As New Rectangle(20, 20, 200, 100)
Dim myLGBrush As New LinearGradientBrush(myRect, Color.Blue, _
Color.Red, 0.0F, True)
' Draw a rectangle to the screen using the LinearGradientBrush.
e.Graphics.FillRectangle(myLGBrush, myRect)
' Rotate the LinearGradientBrush.
myLGBrush.RotateTransform(90.0F)
' Scale the gradient for the height of the rectangle.
myLGBrush.ScaleTransform(0.5F, 1.0F)
' Draw to the screen, the rotated and scaled gradient.
e.Graphics.FillRectangle(myLGBrush, 20, 150, 200, 100)
' Rejustify the brush to start at the top edge of the rectangle.
myLGBrush.TranslateTransform(-20.0F, 0.0F)
' Draw a third rectangle to the screen using the translated brush.
e.Graphics.FillRectangle(myLGBrush, 20, 300, 200, 100)
End Sub
適用於
TranslateTransform(Single, Single)
依指定的維度轉譯局部幾何轉換。 這個方法會在轉換前加上轉譯。
public:
void TranslateTransform(float dx, float dy);
public void TranslateTransform (float dx, float dy);
member this.TranslateTransform : single * single -> unit
Public Sub TranslateTransform (dx As Single, dy As Single)
參數
- dx
- Single
x 中轉譯的值。
- dy
- Single
y 中翻譯的值。
範例
如需範例,請參閱 TranslateTransform。