如何根据分辨率调整控件大小?

发布于 2024-12-21 07:53:43 字数 170 浏览 5 评论 0原文

在 WinForms 应用程序内部,处理调整控件大小以匹配基于屏幕分辨率以及最大化和调整窗口大小的最佳方法是什么。我有 3 列是这样设置的。每列中的标签文本框。您可以将其算作 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

绳情 2024-12-28 07:53:43

TL;DR:如果不手动编码调整大小逻辑,您就无法做到这一点。顺便说一句,您可能不应该尝试这样做。

据我所知,在传统的 WinForms 中,如果不推出您自​​己的解决方案,就没有自动的方法。 Sean87 建议 AutoScaleMode 属性,但虽然它是自动的,但它不支持按分辨率自动调整大小。它提供了一个基于 Windows 中的字体大小设置或 DPI 设置进行缩放的选项。当简单地更改屏幕分辨率时,这些都不会直接更改,而且老实说,大多数典型用户(甚至可能是高级用户)可能永远不会修改 DPI 或字体大小设置。

此外,从基本用户的角度来看,增加屏幕分辨率的重点是提供更多的虚拟桌面“空间”来放置应用程序窗口。确实,现在大多数显示器都是基于 LCD 的,因此具有 原生分辨率使得改变这一点基本上成为了 CRT 过去的事情。但是,购买更大的新显示器的行为仍然会让典型用户增加虚拟屏幕空间,以便他们可以同时在屏幕上看到更多窗口。我认为,始终保持与屏幕分辨率相同的相对尺寸的应用程序是相当不常见的,并且违背了大多数用户的期望,甚至包括我们高级开发人员用户。

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

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

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.

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.

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.

我还不会笑 2024-12-28 07:53:43

您没有定义“列”的含义。通常,您应该使用 TableLayoutPanel 并在每个“单元格”内设置控件的锚点。

You don't define what you mean by "column". Generally, you should use a TableLayoutPanel and inside each "cell", set the anchors of the controls.

苦行僧 2024-12-28 07:53:43

您可以更改表单的 AutoScaleMode 以及每个控件的自动大小属性。您可以使用 splitcontainer 或面板来形成您的列。

you can change AutoScaleMode of the form and also auto size property of each control. And you might use splitcontainer or panels to form your columns.

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