event when Z-order change?

L

Lloyd Dupont

Is there any event/method I could override in of my container control if a
children is BringToFront() / SendToBack() ?

I have a custome container control with scroll bar.
I would like my scroll bar to alway be on top and if other child control are
moved up or down, I would like to move my scroll bar on top again after
that.

any clues? tips? links? other?
thanks!

--
Regards,
Lloyd Dupont

NovaMind development team
NovaMind Software
Mind Mapping Software
<www.nova-mind.com>
 
T

Tim Scott

Lloyd,

The Z-Order is controlled by the order of the controls in the parent
control's Control collection.

You can set something to be top-most in the Z-order by making it first
in the controls collection. For example:

// C#
// "this" is a class derived from Form.
this.SuspendLayout();
this.Controls.SetChildIndex(myScrollBar, 0);
this.ResumeLayout();

See the Controls property (a ControlCollection of Control objects).
From MSDN:
"When SetChildIndex is called, the Control referred to by the child
parameter is moved to the position specified by newIndex and the other
Control references in the Control.ControlCollection are reordered to
accommodate the move. The control with an index value of zero is at the
top of the z-order, and higher numbers are closer to the bottom"
From
http://msdn.microsoft.com/library/d...lControlCollectionClassSetChildIndexTopic.asp

You'll still have to figure out when new controls are added to the
parent control, and then use the code to reorder the child controls.

Good luck!

-- Tim S.
 
L

Lloyd Dupont

Hi Tim,

Paying attention to when a Control is added or removed is easy:
OnControlAdded & OnControlRemoved is here just for that.

But even after reading SetChildIndex documentation I still don't know how my
container could automatically pick up when a developer/user call
SetChilIndex/BringToFront/SendToBack on child control (s)he added to my view
:-(
 
T

Tim Scott

Lloyd,

There is a Control.UpdateZOrder() method that's probably called when a
control's Z-order changes. But it's marked as protected void; so you
can't directly override it. You may be out of luck.

Thinking outside of the code for a moment, and along the path of API
and component design...can you 'require' that a developer using your
scrollbar make sure that it is on top? For example, make it their
responsibility to place it on top. I can see how you'd want your
control to be on top no matter what, so that the developer doesn't have
to worry about it; but the other approach gives your user-developer
more control.

What if they had some other control on the same container that thinks
-it- should be topmost? Your control and the other control would be
fighting over the topmost z-order. Even if you could assure in code
that your control was always top-most, it may not be the best thing
from a component usability point of view.

Lloyd, I know this wasn't much help, but good luck!

-- Tim Scott
http://geekswithblogs.net/tscott
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

get key state 1
inspector window problem 1
Japaneese IME 4
AnimateWindow and popup window 1
track app activation 2
what could prevent an Invalidate() from re-Drawing? 5
DirectX & C# 2.0 2
winform problem 2

Top