如何随着分辨率的变化自动调整大小和调整表单控件
我注意到某些应用程序会更改控件的位置以尽可能适应当前的分辨率。例如,如果窗口最大化,则控件的设置方式应使整个 GUI 看起来平衡。
是否可以使用 C# 在 Visual studio 2010 中制作或实现此功能?
I have noticed that some applications change their controls' positions to fit themselves as much as possible in the current resolution. For example, if the window is maximized, the controls are set in such a way that the overall GUI looks balanced.
Is it possible to make or implement this functionality in Visual studio 2010 using C#?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
使用 Dock 和 锚点属性。 这里是一个很好的文章。请注意,这些将在最大化/最小化时处理更改。如果屏幕分辨率发生变化,情况会略有不同,但原理相同。
Use Dock and Anchor properties. Here is a good article. Note that these will handle changes when maximizing/minimizing. That is a little different that if the screen resolution changes, but it will be along the same idea.
使用这些组合来获得所需的结果:
将
Anchor
属性设置为None,控件将不会调整大小,它们只会移动其位置。将
Anchor
属性设置为 Top+Bottom+Left+Right,控件将调整大小,但不会改变其位置。将表单的
最小大小
设置为适当的值。设置
Dock
属性。使用
Form Resize
事件来更改你想要的任何内容我不知道字体大小(标签,文本框、组合框等)在(1)-(4)中会受到影响,但在(5)中可以控制。
Use combinations of these to get the desired result:
Set
Anchor
property to None, the controls will not be resized, they only shift their position.Set
Anchor
property to Top+Bottom+Left+Right, the controls will be resized but they don't change their position.Set the
Minimum Size
of the form to a proper value.Set
Dock
property.Use
Form Resize
event to change whatever you wantI don't know how font size (label, textbox, combobox, etc.) will be affected in (1) - (4), but it can be controlled in (5).
..并检测分辨率的变化来处理它(一旦您像 SwDevMan81 建议的那样使用对接和锚定),请使用 SystemEvents.DisplaySettingsChanged 事件 in Microsoft.Win32。
..and to detect a change in resolution to handle it (once you're using Docking and Anchoring like SwDevMan81 suggested) use the SystemEvents.DisplaySettingsChanged event in Microsoft.Win32.
抱歉我迟到了才看到问题
这是一个简单的编程解决方案,对我来说效果很好,
创建这些全局变量:
加载后,填充这些变量;
然后选择您的表单并将这些代码放入表单的 SizeChange 事件中;
我希望这会有所帮助,它在我的项目中完美运行。
sorry I saw the question late,
Here is an easy programmatically solution that works well on me,
Create those global variables:
after on load, fill those variables;
then select your form and put these code to your form's SizeChange event;
I hope this helps, it works perfect on my projects.
在这里我喜欢使用 https://www.netresize.net /index.php?c=3a&id=11#buyopt。但它是付费版本。
如果您购买 1 个站点许可证(无限开发者),您还可以获得他们的源代码。
我如何找到 nuget 包解决方案。
Here I like to use https://www.netresize.net/index.php?c=3a&id=11#buyopt. But it is paid version.
You also can get their source codes if you buy 1 Site License (Unlimited Developers).
How ever I am finding the nuget package solution.
在页面加载时为所有控件添加此代码或在容器中添加所有控件
add this code at page load do for all control or add all control in containers
在表单加载事件中添加这一行
in the form load event add this line