Rectangle.Offset 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
依指定的數量調整這個矩形的位置。
多載
| 名稱 | Description |
|---|---|
| Offset(Point) |
依指定的數量調整這個矩形的位置。 |
| Offset(Int32, Int32) |
依指定的數量調整這個矩形的位置。 |
Offset(Point)
- 來源:
- Rectangle.cs
- 來源:
- Rectangle.cs
- 來源:
- Rectangle.cs
- 來源:
- Rectangle.cs
- 來源:
- Rectangle.cs
依指定的數量調整這個矩形的位置。
public:
void Offset(System::Drawing::Point pos);
public void Offset(System.Drawing.Point pos);
member this.Offset : System.Drawing.Point -> unit
Public Sub Offset (pos As Point)
參數
- pos
- Point
金額可以抵銷地點。
範例
以下程式碼範例展示了 Contains、 以及 Offset 方法以及類別 SystemPens 。 此範例設計用於 Windows 表單。 將此程式碼貼入包含名為 Button1、從表單建構子或DrawFirstRectangle方法呼叫Load的按鈕的表單中,並將該方法與按鈕事件Button1_Click關聯Click。
private:
[UIPermission(SecurityAction::Demand, Window=UIPermissionWindow::AllWindows)]
void DrawFirstRectangle()
{
Rectangle rectangle1 = Rectangle(70,70,100,150);
ControlPaint::DrawReversibleFrame( rectangle1, SystemColors::Highlight, FrameStyle::Thick );
}
void Button1_Click( Object^ /*sender*/, EventArgs^ /*e*/ )
{
Rectangle rectangle1 = Rectangle(70,70,100,150);
// Get the bounds of the screen.
Rectangle screenRectangle = Screen::PrimaryScreen->Bounds;
// Check to see if the rectangle is within the bounds of the screen.
if ( screenRectangle.Contains( rectangle1 ) )
{
ControlPaint::DrawReversibleFrame( rectangle1, SystemColors::Highlight, FrameStyle::Thick );
// Call the Offset method to move the rectangle.
rectangle1.Offset( 20, 20 );
// Draw the new, offset rectangle.
ControlPaint::DrawReversibleFrame( rectangle1, SystemColors::Highlight, FrameStyle::Thick );
}
}
Rectangle rectangle1 = new Rectangle(70, 70, 100, 150);
private void DrawFirstRectangle()
{
ControlPaint.DrawReversibleFrame(rectangle1,
SystemColors.Highlight, FrameStyle.Thick);
}
private void Button1_Click(object sender, EventArgs e)
{
// Get the bounds of the screen.
Rectangle screenRectangle = Screen.PrimaryScreen.Bounds;
// Check to see if the rectangle is within the bounds of the screen.
if (screenRectangle.Contains(rectangle1))
// If so, erase the previous rectangle.
{
ControlPaint.DrawReversibleFrame(rectangle1,
SystemColors.Highlight, FrameStyle.Thick);
// Call the Offset method to move the rectangle.
rectangle1.Offset(20, 20);
// Draw the new, offset rectangle.
ControlPaint.DrawReversibleFrame(rectangle1,
SystemColors.Highlight, FrameStyle.Thick);
}
}
Dim rectangle1 As New Rectangle(70, 70, 100, 150)
Private Sub DrawFirstRectangle()
ControlPaint.DrawReversibleFrame(rectangle1, _
SystemColors.Highlight, FrameStyle.Thick)
End Sub
Private Sub Button1_Click(ByVal sender As Object, _
ByVal e As EventArgs) Handles Button1.Click
' Get the bounds of the screen.
Dim screenRectangle As Rectangle = Screen.PrimaryScreen.Bounds
' Check to see if the rectangle is within the bounds of the screen.
If (screenRectangle.Contains(rectangle1)) Then
' If so, erase the previous rectangle.
ControlPaint.DrawReversibleFrame(rectangle1, _
SystemColors.Highlight, FrameStyle.Thick)
' Call the Offset method to move the rectangle.
rectangle1.Offset(20, 20)
' Draw the new, offset rectangle.
ControlPaint.DrawReversibleFrame(rectangle1, _
SystemColors.Highlight, FrameStyle.Thick)
End If
End Sub
備註
此方法水平方向以指定點的 x 座標調整左上角位置,垂直方向則依指定點的 y 座標調整。
適用於
Offset(Int32, Int32)
- 來源:
- Rectangle.cs
- 來源:
- Rectangle.cs
- 來源:
- Rectangle.cs
- 來源:
- Rectangle.cs
- 來源:
- Rectangle.cs
依指定的數量調整這個矩形的位置。
public:
void Offset(int x, int y);
public void Offset(int x, int y);
member this.Offset : int * int -> unit
Public Sub Offset (x As Integer, y As Integer)
參數
- x
- Int32
水平偏移。
- y
- Int32
垂直偏移量。