屏幕分辨率问题 VS2008 - C++命令行界面
我有一个大小为 800x600 的程序。
我想让这个程序在最大化时扩展,以便所有元素(按钮、图片框)改变大小以适应新的比例,具体取决于用户窗口屏幕分辨率。
我想解决这个问题的方法是采用用户的屏幕分辨率并手动更改所有内容的大小,并对所有常见的分辨率执行此操作,如果用户有一些罕见的分辨率,我会这样做,以便最大化/最小化按钮禁用。
但这会非常非常耗时,因为表单中有很多元素,而且它们有多种形式......
基本上,有没有捷径?也许是 VS2008 的内置功能或某种插件。
有哪些方法可以解决这个问题?
I have a program that has a SIZE of 800x600.
I want to make this program expand if it is maximized, so that all the elements(buttons, picturebox's) change size to fit the new ratio depending on the users windows screen resolution.
The way I am thinking to approach this is to take the users screen resolution and manual change the size of everything, and do this for all common resolutions, if a user has some rare resolution, ill just make it so the maximize/minimize buttons are disabled.
But this will be very very time consuming as there are lots of elements in the forms, and their are multiple forms.....
Basically, is there a shortcut? Perhaps a built in feature or some kind of add in for VS2008.
What are some methods to tackle this issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能已经注意到,几乎每个 Windows 程序都有一个最大化按钮。所以这肯定是一个普遍的问题,并且确实有现有的解决方案。
通常你不会搞乱固定的分辨率。这确实是一场失败的游戏,即使只是因为任务栏占用了未指定的空间量。即使您煞费苦心地枚举了所有不同的情况,您可能也必须为 Windows 8 重做。
相反,您通常会在不同的控件上分配“额外”空间。例如,由于您的应用程序的最小尺寸为 800x600,因此 1024x732 桌面上的额外空间将为水平 224 英寸和垂直 132 英寸。您的菜单栏很可能已经知道如何处理这个问题:它占用 100% 的额外水平空间和 0% 的垂直空间。对于窗口中的其他控件,您可以定义类似的百分比。通常分配的百分比是 0% 和/或 100%。在 WinForms 中,您只需将其告诉您的 Windows 布局引擎。
此外,您还应该对控件使用相对定位。例如,如果窗口左侧有一个 100% 可扩展的文本编辑器,右侧有一个固定按钮,那么您应该将该按钮相对于右边缘定位。在 WinForms 中,这可以通过 Anchor 属性来实现。
ASs you've probably noted, almost every Windows program has a maximize button. So this is certainly a common problem, and there are indeed existing solutions.
Typically you don't mess with fixed resolutions. This is really a losing game, if only because the taskbar takes away an unspecified amount of space. Even if you painstakingly did enumerate all different cases, you would probably have to redo it for Windows 8.
Instead, you typically distibute the "extra" space over the different controls. For instance, since your app is a minimum of 800x600, the extra space on a 1024x732 desktop would be 224 horizontally and 132 vertically. Your menu bar most likely already knows how to deal with this: it takes 100% of the extra horizontal space, and 0% of the vertical space. For other controls in your window, you can define similar percentages. Often the precentages assigned are 0% and/or 100%. In WinForms, you just need to tell this to your windows layout engine.
Furthermore, you also should use relative positioning for your controls. For instance, if you have an 100% expandable textedit on the left of your window, and a fixed button on the right, then you should position that button relative to the right edge. In WinForms, this can be achieved via the Anchor property.