Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding the top most(z-order) control in a panel

See my case is,

I am opening more than one forms (toplevel=false) inside a panel. All the forms opened inside that panel will be dock filled and brought to front during runtime. and my need in this situation is, how can i select the top most control(form) on that panel. Top most control means control(form) which is having greater z-order.

I am currently using this code by assumption,

 panel.controls(0)

Can any body tell me, whether the above snippet is right or any alternate syntax available in dot net to achieve that.?

like image 588
Rajaprabhu Aravindasamy Avatar asked Mar 05 '13 13:03

Rajaprabhu Aravindasamy


2 Answers

According to the MSDN:

The control with an index value of zero is at the top of the z-order, and higher numbers are closer to the bottom.

Therefore, I'd say your assumption was correct. Controls(0) will always be the top-most control. The only concern would be whether or not it is visible.

like image 150
Steven Doggart Avatar answered Nov 14 '22 18:11

Steven Doggart


I don't see any other solution of looping through each Control and see what's the topmost one. Something like:

Dim TopMostControl As Control = panel.Controls(0) 'Check if there are any control
For Each Control As Control In panel.Controls
    If panel.Controls.GetChildIndex(Control) < panel.Controls.GetChildIndex(TopMostControl) Then
        TopMostControl = Control
    End If
Next
like image 1
Jamby Avatar answered Nov 14 '22 18:11

Jamby