如何缩放表单上的控件以按比例适合表单?
我有一个 Visual Basic 2010 表单,其中包含各种组框、按钮和标签。我希望能够使表单最大化,但是当我这样做时,控件保持在原来的位置,并且它们不会随表单调整大小。我希望它们能够与表单成比例地调整大小。任何帮助将不胜感激。
I have a visual basic 2010 form with various group boxes, buttons, and labels. I want to be able to have the form maximized, but when I do that the controls stay where they are at and they do not resize with the form. I want them to resize proportionately with the form. Any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
设 form1 是表单,
gb_check 是表单内的一个组框,
Groupbox
的高度、位置和宽度可以相对于表单大小进行如下设置:如果您有组框内的控件其大小相对于组框设置
Let form1 is the form,
gb_check be a group box inside the form
the
height, location and width
of theGroupbox
can be make relative to the form size as followsIf you have controls inside the group box its size set relative to the group box
这才是正确的做法!为了使每种屏幕分辨率都能正确显示,请使用 .net 框架中提供的布局!您不需要编辑任何边距或任何其他内容。
It's the correct way ! In order to have a correct display for every screen resolution use the layouts provided in the .net framework ! You don't need to edit any margin or what so ever.
Dim res As New SizeF(Screen.PrimaryScreen.WorkingArea.Width / Me.Size.Width, Screen.PrimaryScreen.WorkingArea.Height / Me.Size.Height)
Me.Scale(res)
Dim res As New SizeF(Screen.PrimaryScreen.WorkingArea.Width / Me.Size.Width, Screen.PrimaryScreen.WorkingArea.Height / Me.Size.Height)
Me.Scale(res)
您可以根据窗体的大小设置 ResizeEnd 或 Resize 事件控件的位置和大小。您需要确保当表单最小化或变得非常小时它不会崩溃。
You can set the position and size of the controls form ResizeEnd or Resize event, based on form's size. You will need to make sure it doesn't crash when the form is minimized or made very small.
实际上,我最终使用表格布局面板来排列所有内容,使其与屏幕尺寸成比例。如果您的控件布置在网格中,它会非常有效。
I actually ended up using the table layout panel to arrange everything to proportion with the screen size. It works quite nicely if your controls are laid out in a grid.