如何在窗口最大化时调整控件大小 [英] how to resize controls when the window is maximized

查看:79
本文介绍了如何在窗口最大化时调整控件大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道当窗口在C#中最大化时如何调整窗体上的控件大小以使窗体最大化或拉伸控件将保留彼此的部分

I'd like to know how to resize controls on a form when a window is maximized in C# so that id the form is maximized or strethced the controls will retain there porportion to each other

推荐答案

如果这是WPF,我会说:全速前进,但是,如果这是Win Form:



约7几天前,在Windows窗体应用程序的上下文中,有一个类似的问题,您可能会在OP中找到我的对话框(在注释中),并且我发布的(解决方案)解决方案很有用:[ ^ ]。



您可能还会发现有关此质量保证问题的讨论:[ ^ ]。



但是,我建议你不要试图dy除非绝对必要,否则将重新调整Win Form控件的重新调整大小和重新定位:imho,太多的工作以获得太少的返回,并且很有可能任意重新调整大小将导致UI看起来像可怕。



使用标准的Control属性'DockStyle和'Anchor,通常可以获得相当不错的结果。并且,你是否真的想尝试扩展像字体这样的东西,因为基于光学尺寸的提示的工作原理,它们在某些尺寸上可能看起来不太好?



如果手头的任务是确保我的表单在两种情况下按比例重新调整大小:正常视图和最大化视图,我会通过简单地计算两个布局并切换它们来实现当Form的SizeChanged事件被触发时。



如果您需要帮助,请询问。
If this is WPF, I'd say: "full speed ahead," but, if this is Win Forms:

About 7 days ago, in the context of a Windows Form Application, there was a similar question, and you might find my dialog (in the comments) with the OP, and my posted (outline of a) "solution" useful: [^].

You may also find the discussion on this QA question relevant: [^].

But, I advise you against attempting dynamic re-sizing and re-positioning of Win Form Controls unless absolutely necessary: imho, too much work for too little a return, and a good chance that arbitrary re-sizing will result in a UI that looks terrible.

You can usually get pretty good results using the standard Control properties 'DockStyle, and 'Anchor. And, do you really want to try and scale things like Fonts where they may not look very good at certain point sizes because of the way that "optical size-based hinting" works ?

If the task at hand was to make sure that my Form looked proportionally re-sized in only two cases: "normal" view, and "maximized" view, I would approach that by simply calculating two layouts, and switching them as the Form's SizeChanged Event was triggered.

If you want help with that, just ask.


这篇关于如何在窗口最大化时调整控件大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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