简体   繁体   English

(C#) SuspendLayout 是否级联到子控件?

[英](C#) Does SuspendLayout cascade to child controls?

C#: Does SuspendLayout cascade to child controls? C#:SuspendLayout 是否级联到子控件?

Do I have to iterate the child of the control myself to call suspendlayout on them?我是否必须自己迭代控件的子项才能对它们调用 suspendlayout? and on their grand child?和他们的孙子? grand grand child??大孙子?? grand grand grand child?大孙子?

Thanks谢谢

SuspendLayout doesn't propagate recursively, but depending on what you are doing, suspending just specific controls may be enough. SuspendLayout不会递归传播,但取决于您在做什么,仅暂停特定控件可能就足够了。

The rule of a thumb is: you suspend the control whose layout you are about to mess with more than once.经验法则是:您暂停要多次弄乱其布局的控件。

For instance:例如:

  • If a control contains a number of children, and you intend to add one, you don't need to suspend anything.如果一个控件包含多个子项,并且您打算添加一个,则不需要挂起任何内容。
  • If you intend to add more than one child to the parent, you should suspend the parent.如果您打算向父级添加多个子级,则应暂停父级。
  • If you intend to change the Size property of one child, no need to suspend anything.如果您打算更改一个孩子的Size属性,则无需暂停任何内容。 The child will be changed only once, and that will, in turn, cause only one change in the parent.子项只会更改一次,而这反过来只会导致父项发生一次更改。
  • If you intend to change the Size of multiple children, you should only suspend the parent.如果您打算更改多个子项的Size ,则应仅暂停父项。 Children only get one resize each, so no need to suspend them.孩子们每个只能调整一次大小,所以不需要暂停他们。 But each one of those children would cause the parent to relayout, so suspend the parent to do all those relayouts in bulk once you call ResumeLayout .但是这些孩子中的每一个都会导致父级重新布局,因此一旦您调用ResumeLayout ,就暂停父级以批量执行所有这些重新布局。
  • If you intend to change, for instance Size , Location and Bounds properties on multiple children, you should suspend both the parent and the children.例如,如果您打算更改多个子项的SizeLocationBounds属性,则应暂停父项和子项。 All of them will have multiple layout events triggering.所有这些都会触发多个布局事件。 Just be sure to only resume the parent after all its children have resumed.请确保仅在其所有子项恢复后才恢复父项。 Otherwise, each of the children's ResumeLayout s would cause a relayout of the parent so you would get no benefit from suspending it in the first place.否则,每个孩子的ResumeLayout s 都会导致父级的重新布局,因此您不会从一开始就挂起它没有任何好处。
  • If a parent has multiple children, but you only wish to change the Size of the parent, no need to suspend anything.如果父级有多个子级,但您只想更改父级的Size ,则无需暂停任何内容。 This will indirectly modify a bunch of children, but the parent is the one doing their modifications so it should already know how to handle that efficiently.这将间接修改一堆孩子,但父母是进行修改的人,所以它应该已经知道如何有效地处理它。 It already does it every time the user resizes the window, for instance.例如,每次用户调整窗口大小时它都会这样做。
  • If more than one of the parent's layout-related properties are getting changed, but none of the children's, only the parent should be suspended.如果不止一个父级的布局相关属性发生更改,但没有更改任何子级,则应仅暂停父级。 The reasoning is the same as for the previous point, only suspending the parent so it itself only produces one layout event.推理与上一点相同,仅暂停父级,因此它本身仅产生一个布局事件。

Yes;是的; SuspendLayout stops the control being painted (or rather layout requests being processed), which by default trickles down the child structure. SuspendLayout 停止正在绘制的控件(或者更确切地说是正在处理的布局请求),默认情况下它会沿着子结构向下传递。

In other words: there is "no-one" calling the paint routine anymore.换句话说:不再有“没有人”调用绘制程序了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM