Reputation: 2623
I have an old system here, that loads user controls into a type of panel, then when a user clicks on a menu item, they find the control, then they call the BringToFront
method on the control, making it the visible user control in the panel.
I need to know how to get the current Front
control in the panel ?
kind regards
Upvotes: 4
Views: 4017
Reputation: 865
As Joe White mentioned in a comment, BringToFront
changes the order of the elements in the Controls collection of a container. So if you do
container.Controls[0]
it will give you the topmost control in that ControlCollection
.
Upvotes: 2
Reputation: 79929
I think you are looking for GetChildIndex
, this will give you the value of the z-oder of the control. So you can test this value for each child control in the current form controls collections, then:
The control with an index value of zero is at the top of the z-order, and higher numbers are closer to the bottom.
Something like:
foreach (Control x in parent.Controls)
{
if(parent.Controls.GetChildIndex(x) == 0)
{
//x is the front most control
}
}
Upvotes: 5