Share via


HOW TO:將控制項和表單邊緣對齊

更新:2007 年 11 月

您可以藉由設定 Dock 屬性,將控制項對齊表單邊緣。這個屬性 (Property) 會指定您的控制項在表單中的位置。您可將 Dock 屬性設為下列值:

設定

對控制項的影響

Bottom

停駐在表單下方。

Fill

填滿表單中剩下的空間。

Left

停駐在表單左方。

None

不會停駐在任何地方,而是出現在 Location 屬性指定的位置。

Right

停駐在表單右方。

Top

停駐在表單上方。

Visual Studio 具有這項功能的設計階段支援。

若要在執行階段設定控制項的 Dock 屬性

  • 在程式碼中將 Dock 屬性設定為適當值。

    ' To set the Dock property internally.
    Me.Dock = DockStyle.Top
    ' To set the Dock property from another object.
    UserControl1.Dock = DockStyle.Top
    
    // To set the Dock property internally.
    this.Dock = DockStyle.Top;
    // To set the Dock property from another object.
    UserControl1.Dock = DockStyle.Top;
    
    // To set the Dock  property internally.
    this.set_Dock(DockStyle.Top);
    // To set the Dock property from another object.
    UserControl1.set_Dock(DockStyle.Top);
    

請參閱

工作

HOW TO:錨定和停駐 FlowLayoutPanel 控制項中的子控制項

HOW TO:錨定和停駐 TableLayoutPanel 控制項中的子控制項

概念

AutoSize 屬性概觀

參考

Control.Dock

Control.Anchor

其他資源

使用 .NET Framework 開發自訂的 Windows Form 控制項