If I have a number of overlapping controls on a Windows form, how can I programmatically change the z-order? I need to change the order in which they are layered. Not just BringToFront or SendToBack but set them in a specific order.
In the call:
this.Controls.AddRange(new System.Windows.Forms.Control[]
{
this.button1,
this.dataGrid1,
this.label1,
this.label4,
this.trackBar1});
the components are added to the frame in the order listed from front to back. That is - button1 is in front, trackBar1 is in the back.
This may not be very elegant but you could try using the CopyTo method to copy the existing Controls array, rearrange the elements externally, Controls.Clear and then add back the controls with Controls.AddRange.
---
dino
Let me know how it works. Depending on how complicated the form is, you may want to bracket the reformating calls with this.SuspendLayout() and this.ResumeLayout() so that it doesn't look too ugly to the user.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.