调整窗体和控件大小以适应不同的屏幕分辨率,Visual Basic VB.NET
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22675641/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Adjust form and control size to different screen resolutions, Visual Basic VB.NET
提问by ballbern
I've created a bit of a problem for myself and im hopping someone here can help with it.
我给自己制造了一些问题,我希望这里的人可以提供帮助。
I've created an app in Visual Basic on my desktop PC with a screen res of 1280x1024 and used images that I've created in illustrator as background images and buttons(the largest images is a backgroud image 1004x804) . It looks great on my desktop but when I run it on my laptop with a screen res of 1366x768 the form height is too large and the bottom portion of the form is cut off.
我在桌面 PC 上用 Visual Basic 创建了一个应用程序,屏幕分辨率为 1280x1024,并使用我在 illustrator 中创建的图像作为背景图像和按钮(最大的图像是背景图像 1004x804)。它在我的桌面上看起来很棒,但是当我在屏幕分辨率为 1366x768 的笔记本电脑上运行它时,表单高度太大并且表单的底部被切断。
So the way im thinking I might be able to fix it is by getting the screen res on form load and checking it against the form size then resizing the form. This is the code im using on form load to do this.
所以我认为我可能能够修复它的方式是通过在表单加载时获取屏幕分辨率并根据表单大小检查它然后调整表单大小。这是我在表单加载时使用的代码。
Dim intH As Integer = Screen.PrimaryScreen.Bounds.Height
Dim intW As Integer = Screen.PrimaryScreen.Bounds.Width
If Me.Height > intH Then
Me.Height = intH
Me.Width = intW
End If
But the problem is that I want everything including all the controls (that are pictureBoxs with background images) to be adjusted to about 50% of the screen size if the form is larger than the height or width…. I can't work out how to do this, if it's possible or if it's the best way to go about solving this problem. Can someone nudge me in the right direction please?
但问题是,如果表单大于高度或宽度,我希望包括所有控件(带有背景图像的图片框)在内的所有内容都调整到屏幕大小的 50% 左右...... 如果可能,或者这是解决此问题的最佳方法,我无法弄清楚如何执行此操作。有人可以朝正确的方向轻推我吗?
回答by Adam Zuckerman
You can either write code in the form's Resize event to move all of the controls and set their sizes or you can go through the form designer to set the controls to lock to a specific side and resize accordingly. You can find a decent tutorial here(about halfway down the page) and another one here.
您可以在表单的 Resize 事件中编写代码来移动所有控件并设置它们的大小,或者您可以通过表单设计器将控件设置为锁定到特定一侧并相应地调整大小。你可以在这里找到一个不错的教程(大约页面的一半)和另一个在这里。

