可以通过TableLayoutPanel和Anchor属性在Dock中对齐和拉伸控件。
对齐和拉伸控件
在 Visual Studio 中,将TableLayoutPanel工具箱中的控件拖到窗体上。
将 Button 控件从 工具箱 拖到 TableLayoutPanel 控件的左上角单元格中。 控件 Button 居中位于单元格中。
将控件Button的属性的值Anchor设置为
Top,Bottom
。 该控件 Button 被拉伸以匹配单元格的高度。将控件Button的属性的值Dock设置为 None。 该 Button 控件返回其原始大小,并移动到单元格的左上角。 Windows 窗体设计器已将Anchor属性
Top, Left
设置为 。将控件Button的属性的值Anchor设置为
Bottom,Right
。 该 Button 控件移动到单元格的右下角。