Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(C#) Does SuspendLayout cascade to child controls?

Tags:

c#

controls

C#: Does SuspendLayout cascade to child controls?

Do I have to iterate the child of the control myself to call suspendlayout on them? and on their grand child? grand grand child?? grand grand grand child?

Thanks

like image 942
Led Avatar asked Oct 28 '09 01:10

Led


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.

Is C language easy?

C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.

What is C in C language?

What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.


1 Answers

SuspendLayout doesn't propagate recursively, but depending on what you are doing, suspending just specific controls may be enough.

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. 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. 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.
  • If you intend to change, for instance Size, Location and Bounds properties on multiple children, you should suspend both the parent and the children. 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 ResumeLayouts would cause a relayout of the parent so you would get no benefit from suspending it in the first place.
  • If a parent has multiple children, but you only wish to change the Size of the parent, no need to suspend anything. 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.
like image 150
relatively_random Avatar answered Oct 15 '22 03:10

relatively_random