什么是Control.GetPreferredSize方法的目的是什么? [英] What is the purpose of Control.GetPreferredSize method?

查看:930
本文介绍了什么是Control.GetPreferredSize方法的目的是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在执行其大小取决于某些属性更改用户的控制。据我了解的WinForms布局引擎请求时,它进行布局,并通知他们关于他们能够承受的最大尺寸的首选大小每个子控件。



这是一本介绍 的getPreferredSize在MSDN:




  Control.GetPreferredSize(大小proposedSize)

检索到其中一个控制可装配的矩形区域的大小。




我是通过以下困惑:




您可以返回一个大小比$指示的
约束较大b $ b proposedSize参数,但
proposedSize应该减少为
约束减小。




这是什么意思?如果我回到大小比建议的大,会发生什么?



有人可以解释我是如何工作的呢?


解决方案

什么该行的意思是,你可以自由地获得超过 proposedSize 参数较大的首选大小,但 proposedSize 应该还是会影响您的首选尺寸。例如,你的的getPreferredSize返回的大小(新尺寸(100,0)的getPreferredSize(新尺寸(200小于返回的大小, 0))



请注意,没有什么不好的事情发生,如果你返回一个尺寸较大;布局引擎将通过一切理清你,可能减少了可用于其它控制的大小。最终,你的首选尺寸仅仅是发动机的一个提示,以便它知道什么相对空间需求是它安排的各种UI组件。


I'm working on implementing a user control that changes its size depending on some properties. As I understand winforms layout engine asks each child control for its preferred size when it performs a layout and informs them about the maximum size that they can afford.

This is a description of GetPreferredSize in msdn:

Control.GetPreferredSize(Size proposedSize)

Retrieves the size of a rectangular area into which a control can be fitted.

I'm confused by the following:

You can return a size larger than the constraints indicated in the proposedSize parameter, but proposedSize should decrease as the constraint decreases.

What does it mean? What will happen if I return the size larger than proposed?

Can somebody explain me how does this work?

解决方案

What that line means is that you are free to return a larger preferred size than the proposedSize parameter, but that proposedSize should still be affecting your preferred size. For example, your returned size for GetPreferredSize(new Size(100, 0) should be less than the returned size for GetPreferredSize(new Size(200, 0)).

Note that nothing bad happens if you return a larger size; the layout engine will sort everything out for you, possibly by reducing the size available for another control. Ultimately, your preferred size is just a hint for the engine, so that it knows what the relative space demands are for the various UI components it is arranging.

这篇关于什么是Control.GetPreferredSize方法的目的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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