调整具有不同屏幕分辨率的控件的大小 [英] resize controls with different screen resolution

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

问题描述

代码以在不同屏幕分辨率下调整按钮等控件的大小

code to resize controls such as buttons etc on different screen resolutions

推荐答案

您应该考虑使用控件的Dock和anchor属性,这将自动调整控件的大小调整窗口大小后.使用Dock和锚属性 [ ^ ]是一个不错的起点.

祝您好运
You should look into using Dock and anchor properties of the controls, which will automatically resize controls whne the window is resized.Manage WinForms controls using Dock and Anchor properties[^] is a good place to start.

Good Luck


如果您使用的是直接Winform,则可以,但它永远不会非常有效,而且表单越复杂,效果越差.问题在于,尽管仅通过使用Anchor属性就可以使控件本身随着表单大小的变化而增大和缩小,但这不会影响文本大小.因此,如果放大按钮,最终将得到一个手形大小的按钮,一个文本是指甲大小的按钮.

您可以通过处理每个控件的Resize事件并适当地修改字体来解决这个问题,但这麻烦很多.

锚点可以很好地工作,只要您谨慎选择要锚定的控件,以及到什么位置-看看VS-调整大小就很好,而根本不会拉伸控件.

恐怕唯一的另一种选择是WPF.
If you are using straight winforms, then you can, but it is never very effective, and the more complex your form, the worse the effect gets. The problem is that while it is possible to make the controls themselves grow and shrink in response to changes in the form size just by playing with the Anchor property, this does not affect the text size. So if you enlarge a button, you end up with a button the size of your hand, with text the size of your fingernail.

You can get round this by handling the Resize event for each control, and modifying teh font appropriately, but it''s a heck of a lot of hassle.

The anchor can work very well, provided you are careful about which controls you anchor, and to where - lookl at VS - it resizes nicely, without stretching controls at all.

The only other alternative is WPF, I''m afraid.


您最好的选择是给出一个不错且正确的表单布局,而无需特殊的代码来调整大小.为了补充Wayne和Griff的答案,我想说Dock是很好并且非常重要,但是它也需要Padding,最好避免使用Anchor.首先,Anchor容易闪烁,但它也需要手动定位(如居中)或硬编码的左/右(上/下)空格,这不太好.

在一个好的设计中,您在层次结构中使用了许多加法Panels,而从不绝对定位和使用任何控件.在某些情况下,某些间隔"面板也很有用.限制表格的最小大小也很重要.

设计良好的布局可正确调整自身大小,而无需处理调整大小事件.

另请参阅我过去对相关问题的回答:
当屏幕分辨率改变时,Zom Out发生故障 [ ^ ],
GUI外观-C#.Net [如何停靠按钮,以便可以使用以下形式进行调整 [
Your best bet to give a nice and correct form layout which does not need special code for resizing. To add to the answers by Wayne and Griff, I would say, that Dock is good and very important, but it also needs Padding, and Anchor is best avoided. First, Anchor is tends to flicker, but it also requires manual positioning (like centering) or hard-coded left/right (top/bottom) spaces, which is not so nice.

In a good design, you use many addition Panels in hierarchy and never absolute positioning and any controls at all. Also some "spacer" panels are useful in some situations. It''s also very important to limit minimum size of the form.

Well designed layout resize itself correctly without processing of resize event.

Please see also my past answers to related questions:
Zom Out malfunctions when Screen resolution changes[^],
GUI Apperance - C#.Net[^].

In this one I''ve shown some simplest code sample: how to dock button so that it can adjust with the form[^].

—SA


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

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