答案 0 :(得分:1)
对于WinForms,请使用包含3列的TableLayoutPanel
,宽度设置为33.33%。在每个面板中放置一个按钮,将其Dock属性设置为Fill,并使用Anchors拉伸整个TableLayoutPanel
。
对于WPF,您将使用Grid
控件。
答案 1 :(得分:0)
使用过的代码来执行此操作。只需将此代码添加到表单中。
Private Sub Form1_SizeChanged(sender As Object, e As EventArgs) Handles Me.SizeChanged
Button1.Width = (Me.Width - 100) / 3 - 10 'That "10" in the last comes from 15*2/3 .So if the space2 is 15 this number must be 10.
Button2.Width = (Me.Width - 100) / 3 - 10 'That "Me.Width - 100" comes from 2*50 .If you want space1 50,this number must be 100.
Button3.Width = (Me.Width - 100) / 3 - 10 'Resize the last.
Me.Button1.Location = New Point(50, Button1.Location.Y) 'Start from 50 in X Coordinate.
Me.Button2.Location = New Point(Button1.Width + 65, Button2.Location.Y) 'That 65 means "50 + 15".(50 is space1,15 is space2.)
Me.Button3.Location = New Point(Button1.Width + Button2.Width + 80, Button3.Location.Y) 'As you expected "50 + 15 + 15 = 80"
'This works for only 3 buttons(horizontally).Get the logic and improve your code for your button count.
End Sub
您可以在此处看到我在我的代码中使用的space1
和space2
。如果您的表单为SizeChanged
,那么3个按钮会按比例调整大小。