views:

123

answers:

1

I have a container control (a Panel) that has a number of Forms loaded into it. Based on user interaction, I .BringToFront() certain forms. However, in other parts of the program, I would like to figure out which form is currently in front. (In other words, determine which was the last form to have its .BringToFront() method called.)

What's the best way to go about determining which control is in front?

A: 

You can use the GetChildIndex method of the Controls collection to get the index of a particular child control.

this.Controls.GetChildIndex(myControl);

The highest value is on top.

Volte
Picky point: according to the docs, the control with child index 0 is at the top of the z-order, and higher values are closer to the bottom.
itowlson
Thanks for the clarification, itowlson. And thanks for the answer, Volte.
Dylan Bennett