规模WindowsForm [英] Scale WindowsForm

查看:161
本文介绍了规模WindowsForm的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我想要的一切(控制等)通过拖动调整大小时,它与WindowsForm按比例的,使得用户可确定的UI自己的大小。
的图片是不完美的,但我希望它解释它:

Basically, I want everything (Controls etc) to scale with the WindowsForm when resizing it by dragging, so that the user can determine the size of the UI himself. The picture is not perfect, but I hope it explains it:

要做到这一点是使用一个(流量/表)LayoutPanel及相应的锚/跌落性能的最简单的方法,但我觉得这样限制我的设计,目前看起来是这样的:

The easiest way to do this would be to use a (Flow/Table)LayoutPanel and the appropriate Anchor/Drop properties, but I feel like that restricts my design, which currently looks like this:

我的想法是扩展所有的组件时,调整大小()被调用:

My idea was to scale all the components when Resize() is called:

foreach(Control c in Controls){
            c.Scale(scaleFactor);
        }



我的问题是:位置设置不正确,并确定所需的舍入在比例因子导致的不一致。

My problems are: Locations aren't set properly and the rounding needed to determine the 'scaleFactor' leads to inconsistencies.

有没有干净的方式来做到这一切的?我必须用LayoutPanels得到一个干净的方式?

Is there a clean way to do all this? Do I have to use LayoutPanels to get a clean way?

推荐答案

您确定要放大这些文本框和标签也?文本框有一个相当标准高度,例如。你有什么期望,如果该窗口是如此之小,文本太大的按钮/文本框等。

Are you sure that you want to zoom those text boxes and labels, too? Text boxes have a fairly standard height, for example. What do you expect if the window is so small that the text is too large for the buttons/text boxes, etc.?

中的内容的典型大小调整逻辑可调整大小的窗口是一个有点不同。我宁愿创建为groupboxes一个无国界的面板和堆栈/ DOCK一切是这样的:

The typical resizing logic of the contents of a resizable window is a little bit different. I would rather create a borderless panel for the groupboxes and stack/dock everything like this:

如果我调整这个窗口,这将是这样的:

If I resize this window, that will look like this:

顺便说一句,如果按钮调整这样的,我不喜欢。我只使用 =锚左,右他们,这样他们就保持其高度。而且不要忘记设置适当的的minimumSize 的形式。

Btw, I do not like if buttons are resized like this. I would use only Anchor = Left, Right for them so they would preserve their height. And do not forget to set a proper MinimumSize for the form.

这篇关于规模WindowsForm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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