Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the front most control

Tags:

c#

winforms

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

like image 545
Captain0 Avatar asked Oct 27 '25 01:10

Captain0


1 Answers

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
    }
}
like image 82
Mahmoud Gamal Avatar answered Oct 29 '25 18:10

Mahmoud Gamal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!