Ignas Limanauskas
Ignas Limanauskas

Reputation: 2486

What is the draw order (OnPaint / OnPaintBackground event) in child-parent controls?

Using C# .NET Compact Framework I am creating a GUI control that contains and controls children that are also custom controls (i.e. System.Windows.Forms.UserControl). Both, children and parent have custom drawing routines (OnPaint). To better understand and optimize the drawing routines I would like to clarify the draw order under .NET.

(1) What would be the correct order of the following events, when the whole thing is displayed the first time:

(2) Does the order of Control.Invalidate() calls impact the order of OnPaint / OnPaintBackground events?

(3) If child control invokes its own child.Invalidate(), does parent get the OnPaint / OnPaintBackground event too?

(4) How does system determine, which control is parent to which children and vice-versa? Is Control.Parent the only indication of this relationship?

Upvotes: 2

Views: 2862

Answers (1)

lc.
lc.

Reputation: 116498

This isn't really an answer, but you could use some Debug.Print() statements and write a quick program to test 1-3 yourself. Add subscribers to the events you're interested in and see when they occur. Then do what you're suggesting in 2-3 and change the order of Invalidate() calls and observe.

Like I said, not an answer, but certainly a way of discovering the answer.

As for #4, like you are implying, the relationship is two-way. You already have half the relationship with Control.Parent (child->parent). The other half is the Control.Controls collection (parent->children). From how I understand it, think of the relationships as a big unordered tree.

Upvotes: 1

Related Questions