如何缩放表单上的控件以按比例适合表单?

发布于 2024-10-05 06:10:30 字数 123 浏览 11 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

鸩远一方 2024-10-12 06:10:31

设 form1 是表单,

gb_check 是表单内的一个组框,

Groupbox 的高度、位置和宽度可以相对于表单大小进行如下设置:

 Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
            gb_chek.Height = (Me.Height * 30) / 100 'what ever be the form height the group box's height is always 30% of the form size
            gb_chek.Width = (Me.Width * 40) / 100 'what ever be the form width the group box's width is always 40% of the form size
            gb_chek.Location = New Point((Me.Width) / 18, (Me.Height) / 12)' set the location of the form relative to form size;
 End Sub

如果您有组框内的控件其大小相对于组框设置

Let form1 is the form,

gb_check be a group box inside the form

the height, location and width of the Groupbox can be make relative to the form size as follows

 Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
            gb_chek.Height = (Me.Height * 30) / 100 'what ever be the form height the group box's height is always 30% of the form size
            gb_chek.Width = (Me.Width * 40) / 100 'what ever be the form width the group box's width is always 40% of the form size
            gb_chek.Location = New Point((Me.Width) / 18, (Me.Height) / 12)' set the location of the form relative to form size;
 End Sub

If you have controls inside the group box its size set relative to the group box

半葬歌 2024-10-12 06:10:31

这才是正确的做法!为了使每种屏幕分辨率都能正确显示,请使用 .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.

ゃ人海孤独症 2024-10-12 06:10:31

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)

牵强ㄟ 2024-10-12 06:10:30

您可以根据窗体的大小设置 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.

知足的幸福 2024-10-12 06:10:30

实际上,我最终使用表格布局面板来排列所有内容,使其与屏幕尺寸成比例。如果您的控件布置在网格中,它会非常有效。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文