如何根据分辨率调整控件的大小? [英] How can I re-size controls based on resolution?

查看:148
本文介绍了如何根据分辨率调整控件的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在WinForms应用程序中,什么是处理重新调整大小控件以根据屏幕分辨率以及最大化和重新调整窗口大小的最佳方法.我有3列设置像这样.每列中都有LABEL TEXTBOX.您可以将其视为6列.我已尝试在右侧锚定,但问题是第1列中的文本框将与接下来的2列重叠.我也尝试过对接,但这似乎不可行.有没有简单的方法可以做到这一点?

Inside a WinForms application what is the best way to handle re-sizing controls to match based on screen resolution and maximizing and re-sizing the window. I have 3 columns that are set like this. LABEL TEXTBOX in each column. You could count that as 6 columns. I have tried anchoring to the right but the problem there is the textbox in column 1will overlap the next 2 columns. I have also tried docking but that does not seem to do the trick. Is there any easy way of doing this?

推荐答案

TL; DR :您不能不手工编码调整大小的逻辑.附带说明,您可能不应该尝试这样做.

TL;DR: You can't without manually coding resizing logic. As a side note, you probably shouldn't be trying to do this.

在传统的WinForms中,如果不使用自己的解决方案,就无法自动获得我的知识. Sean87 建议 AutoScaleMode 属性,但是虽然它是自动的,但不支持按分辨率自动调整大小.它提供了一个根据Windows中的字体大小设置或DPI设置进行缩放的选项.仅更改屏幕分辨率时,这些参数都不会直接更改,老实说,大多数典型用户(甚至可能是高级用户)可能永远不会修改DPI或字体大小设置.

In traditional WinForms there is no automatic way to my knowledge without rolling your own solution. Sean87 suggested the AutoScaleMode property, but while it is then automatic it doesn't support auto-sizing by resolution. It gives an option for scaling based on Font size settings in Windows or the DPI setting. Neither of these are directly changed when simply changing the screen resolution and, honestly, most typical users (and even probably power users) probably never modify the DPI or font size settings.

此外,从基本的用户角度出发,提高屏幕分辨率的重点是为虚拟桌面提供更多的空间"以放置应用程序窗口.的确,大多数监视器现在都是基于LCD的,因此具有本机分辨率使得更改此内容基本上已成为过去的CRT.但是,购买新的更大的显示器的行为仍然会让典型的用户增加此虚拟屏幕的空间,以便他们可以同时在屏幕上看到更多的窗口.我认为,始终保持与屏幕分辨率相同的相对大小的应用程序非常少见,并且不符合大多数用户的期望,甚至包括我们的高级开发者用户.

Besides, the whole point, from a basic user perspective, of increasing screen resolution is to give more virtual desktop "space" to place application windows in. True, most monitors are LCD-based now and thus have native resolutions that make changing this around mostly a thing of the CRT past. But still, the act of buying a new, larger monitor would let a typical user increase this virtual screen space so that they could see more windows on the screen simultaneously. An application that always maintains the same relative size to the screen resolution would be quite uncommon I think and goes against the expectations of most users, including even us advanced developer users.

通常,您需要对应用程序进行编码,以在调整窗口大小时智能且有用地调整其内容,但是通常,您需要由用户来管理它,因为这是他们的机器和他们的偏好(将其视为我的房子,我的规则"原则).这也是为什么大多数(全部?)应用程序不更改窗口位置的原因,除非由用户直接操作(通过拖动窗口框架等)即可.实际上,所有这些都可能解释了Microsoft为什么选择 not 来包括基于分辨率的任何自动调整大小规则的原因.

Typically, you are to code your application to adjust its contents intelligently and usefully if the window is resized, but generally you defer to the user for managing that as it is their machine and their preference (think of it as the "my house, my rules" principle). This is also why most (all?) applications don't change window positions except when directly manipulated by the user (via dragging the window frame and such). In fact, all of this likely explains why Microsoft chose not to include any automatic sizing rule based on resolution.

这篇关于如何根据分辨率调整控件的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆