tags:

views:

1149

answers:

1

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:

  • parent.OnPaintBackground

  • child.OnPaintBackground

  • parent.OnPaint

  • child.OnPaint

(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?

+1  A: 

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.

lc
Thanks for info. If noone can give a definite answer here, that would be the approach. The problem with logs is that I would be seeing one behavior out of many possible. Knowing some rules would allow smarter implementation.
Ignas Limanauskas