Form.SetDesktopBounds(Int32, Int32, Int32, Int32) 方法

定義

設定桌面座標中表單的界限。

C#
public void SetDesktopBounds(int x, int y, int width, int height);

參數

x
Int32

表單位置的 X 座標。

y
Int32

表單位置的 Y 座標。

width
Int32

表單的寬度。

height
Int32

表單的高度。

範例

下列範例示範如何使用 SetDesktopBounds 方法。 若要執行此範例,請將下列程式碼貼到表單中,其中包含名為 Button2 的按鈕。 確定所有事件都與其事件處理常式相關聯。

C#
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);
    }
}

備註

桌面座標是以螢幕的工作區域為基礎,這會排除工作列。 您可以使用這個方法,在桌面上設定表單的位置和大小。 因為桌面座標是以表單的工作區域為基礎,所以您可以使用這個方法來確保表單在桌面上完全可見。

適用於

產品 版本
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

另請參閱