次の方法で共有


Control.SetBounds メソッド (Int32, Int32, Int32, Int32, BoundsSpecified)

コントロールの指定した範囲を指定した位置とサイズに設定します。

Overloads Public Sub SetBounds( _
   ByVal x As Integer, _   ByVal y As Integer, _   ByVal width As Integer, _   ByVal height As Integer, _   ByVal specified As BoundsSpecified _)
[C#]
public void SetBounds(intx,inty,intwidth,intheight,BoundsSpecifiedspecified);
[C++]
public: void SetBounds(intx,inty,intwidth,intheight,BoundsSpecifiedspecified);
[JScript]
public function SetBounds(
   x : int,y : int,width : int,height : int,specified : BoundsSpecified);

パラメータ

  • x
    コントロールの新しい Left プロパティ値。
  • y
    コントロールの新しい Top プロパティ値。
  • width
    コントロールの新しい Width プロパティ値。
  • height
    コントロールの新しい Height プロパティ値。
  • specified
    BoundsSpecified 値のビットごとの組み合わせ。指定されていないパラメータについては、現在の値が使用されます。

使用例

[Visual Basic, C#, C++] Layout イベントで画面の中央に Form を配置する例を次に示します。これにより、ユーザーがフォームのサイズを変更しても、フォームは中央に配置されます。この例では、 Form コントロールが作成されていることを前提にしています。

 

    Private Sub MyForm_Layout(ByVal sender As Object, _
        ByVal e As System.Windows.Forms.LayoutEventArgs) Handles MyBase.Layout

        ' Center the Form on the user's screen everytime it requires a Layout.
        Me.SetBounds((System.Windows.Forms.Screen.GetBounds(Me).Width / 2) - (Me.Width / 2), _
            (System.Windows.Forms.Screen.GetBounds(Me).Height / 2) - (Me.Height / 2), _
            Me.Width, Me.Height, System.Windows.Forms.BoundsSpecified.Location)
    End Sub

[C#] 
private void MyForm_Layout(object sender, System.Windows.Forms.LayoutEventArgs e)
{
   // Center the Form on the user's screen everytime it requires a Layout.
   this.SetBounds((Screen.GetBounds(this).Width/2) - (this.Width/2),
       (Screen.GetBounds(this).Height/2) - (this.Height/2),
       this.Width, this.Height, BoundsSpecified.Location);    
}

[C++] 
private:
    void MyForm_Layout(Object* /*sender*/, System::Windows::Forms::LayoutEventArgs* /*e*/) {
        // Center the Form on the user's screen everytime it requires a Layout.
        this->SetBounds((Screen::GetBounds(this).Width/2) - (this->Width/2),
            (Screen::GetBounds(this).Height/2) - (this->Height/2),
            this->Width, this->Height, BoundsSpecified::Location);    
    }

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

参照

Control クラス | Control メンバ | System.Windows.Forms 名前空間 | Control.SetBounds オーバーロードの一覧 | Bounds | SetBoundsCore | Layout