Form.SetDesktopBounds 方法

以桌面坐标设置窗体的边界。

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
Public Sub SetDesktopBounds ( _
    x As Integer, _
    y As Integer, _
    width As Integer, _
    height As Integer _
)
用法
Dim instance As Form
Dim x As Integer
Dim y As Integer
Dim width As Integer
Dim height As Integer

instance.SetDesktopBounds(x, y, width, height)
public void SetDesktopBounds (
    int x,
    int y,
    int width,
    int height
)
public:
void SetDesktopBounds (
    int x, 
    int y, 
    int width, 
    int height
)
public void SetDesktopBounds (
    int x, 
    int y, 
    int width, 
    int height
)
public function SetDesktopBounds (
    x : int, 
    y : int, 
    width : int, 
    height : int
)

参数

  • x
    窗体位置的 x 坐标。
  • y
    窗体位置的 y 坐标。
  • width
    窗体的宽度。
  • height
    窗体的高度。

备注

桌面坐标基于屏幕的工作区,该区域不包括任务栏。可以使用此方法设置在桌面上窗体的位置和大小。由于桌面坐标基于窗体的工作区,所以可使用此方法确保您的窗体在桌面上完全可见。

示例

下面的代码示例阐释了如何使用 SetDesktopBounds 方法。若要运行此示例,请将以下代码粘贴到一个包含名为 Button2 的按钮的窗体中。确保所有事件都与其事件处理程序关联。

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
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);
    }
}
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(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.get_Location().get_X() + 10, 
            this.get_Location().get_Y() + 10, this.get_Width() - 10, 
            this.get_Height() - 10);
        // Call Sleep to show the form gradually shrinking.
        System.Threading.Thread.Sleep(50);
    }
} //button2_Click

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

Form 类
Form 成员
System.Windows.Forms 命名空间
SetDesktopLocation