Form.SetDesktopBounds(Int32, Int32, Int32, Int32) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
設定桌面座標中表單的界限。
public:
void SetDesktopBounds(int x, int y, int width, int height);
public void SetDesktopBounds (int x, int y, int width, int height);
member this.SetDesktopBounds : int * int * int * int -> unit
Public Sub SetDesktopBounds (x As Integer, y As Integer, width As Integer, height As Integer)
參數
- x
- Int32
表單位置的 X 座標。
- y
- Int32
表單位置的 Y 座標。
- width
- Int32
表單的寬度。
- height
- Int32
表單的高度。
範例
下列範例示範如何使用 SetDesktopBounds 方法。 若要執行此範例,請將下列程式碼貼到表單中,其中包含名為 Button2
的按鈕。 確定所有事件都與其事件處理常式相關聯。
void Button2_Click( System::Object^ sender, System::EventArgs^ e )
{
for ( int i = 0; i <= 20; i++ )
{
// With each loop through the code, the form's
// desktop location is adjusted right and down
// by 10 pixels and its height and width are each
// decreased by 10 pixels.
this->SetDesktopBounds( this->Location.X + 10, this->Location.Y + 10, this->Width - 10, this->Height - 10 );
// Call Sleep to show the form gradually shrinking.
System::Threading::Thread::Sleep( 50 );
}
}
private void Button2_Click(System.Object sender, System.EventArgs e)
{
for(int i = 0; i <= 20; i++)
{
// With each loop through the code, the form's
// desktop location is adjusted right and down
// by 10 pixels and its height and width are each
// decreased by 10 pixels.
this.SetDesktopBounds(this.Location.X+10,
this.Location.Y+10, this.Width-10, this.Height-10);
// Call Sleep to show the form gradually shrinking.
System.Threading.Thread.Sleep(50);
}
}
Private Sub Button2_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button2.Click
Dim i As Integer
For i = 0 To 20
' With each loop through the code, the form's desktop location is
' adjusted right and down by 10 pixels and its height and width
' are each decreased by 10 pixels.
Me.SetDesktopBounds(Me.Location.X + 10, Me.Location.Y + 10, _
Me.Width - 10, Me.Height - 10)
' Call Sleep to show the form gradually shrinking.
System.Threading.Thread.Sleep(50)
Next
End Sub
備註
桌面座標是以螢幕的工作區域為基礎,這會排除工作列。 您可以使用這個方法,在桌面上設定表單的位置和大小。 因為桌面座標是以表單的工作區域為基礎,所以您可以使用這個方法來確保表單在桌面上完全可見。