Control.Dock 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定哪些控制邊界對接到其父控制,並決定控制點如何與父控制進行調整大小。
public:
virtual property System::Windows::Forms::DockStyle Dock { System::Windows::Forms::DockStyle get(); void set(System::Windows::Forms::DockStyle value); };
public virtual System.Windows.Forms.DockStyle Dock { get; set; }
member this.Dock : System.Windows.Forms.DockStyle with get, set
Public Overridable Property Dock As DockStyle
屬性值
這是其中一項 DockStyle 價值。 預設值為 None。
例外狀況
分配的值並非其中之一。DockStyle
範例
以下範例程式碼建立 並 GroupBox 設定其一些常見屬性。 範例中會建立 , TextBox 並將 置 Location 於群組框中。 接著,它設定 Text 群組框的屬性,並將群組框停靠到表單的頂端。 最後,它會透過將屬性false設Enabled為 來停用群組框,這會使群組框內的所有控制項被停用。
// Add a GroupBox to a form and set some of its common properties.
private:
void AddMyGroupBox()
{
// Create a GroupBox and add a TextBox to it.
GroupBox^ groupBox1 = gcnew GroupBox;
TextBox^ textBox1 = gcnew TextBox;
textBox1->Location = Point(15,15);
groupBox1->Controls->Add( textBox1 );
// Set the Text and Dock properties of the GroupBox.
groupBox1->Text = "MyGroupBox";
groupBox1->Dock = DockStyle::Top;
// Disable the GroupBox (which disables all its child controls)
groupBox1->Enabled = false;
// Add the Groupbox to the form.
this->Controls->Add( groupBox1 );
}
// Add a GroupBox to a form and set some of its common properties.
private void AddMyGroupBox()
{
// Create a GroupBox and add a TextBox to it.
GroupBox groupBox1 = new GroupBox();
TextBox textBox1 = new TextBox();
textBox1.Location = new Point(15, 15);
groupBox1.Controls.Add(textBox1);
// Set the Text and Dock properties of the GroupBox.
groupBox1.Text = "MyGroupBox";
groupBox1.Dock = DockStyle.Top;
// Disable the GroupBox (which disables all its child controls)
groupBox1.Enabled = false;
// Add the Groupbox to the form.
this.Controls.Add(groupBox1);
}
' Add a GroupBox to a form and set some of its common properties.
Private Sub AddMyGroupBox()
' Create a GroupBox and add a TextBox to it.
Dim groupBox1 As New GroupBox()
Dim textBox1 As New TextBox()
textBox1.Location = New Point(15, 15)
groupBox1.Controls.Add(textBox1)
' Set the Text and Dock properties of the GroupBox.
groupBox1.Text = "MyGroupBox"
groupBox1.Dock = DockStyle.Top
' Disable the GroupBox (which disables all its child controls)
groupBox1.Enabled = False
' Add the Groupbox to the form.
Me.Controls.Add(groupBox1)
End Sub
備註
利用這個 Dock 屬性來定義如何隨著父控制項的調整而自動調整大小。 例如,設定 Dock 為 會 DockStyle.Left 使控制項與父控制項的左邊對齊,並隨著父控制項的大小調整而調整大小。 控制器以 Z 順序停靠,Z 順序是沿表單 Z 軸(深度)視覺上排列控制項。
控制項可以停靠到其父容器的一邊,或停靠到所有邊並填滿父容器。
將屬性設 Margin 在停靠控制節點上,不會影響控制點與容器邊緣的距離。
給繼承者的注意事項
在導出類別中覆寫該 Dock 屬性時,請使用基底類別的 Dock 特性來擴充基底實作。 否則,你必須提供所有的實作。 您不必同時覆寫 get 該屬性及其 set 方法 Dock ;必要時只需覆寫其中一項。