How to set Z-order of a Control using WinForms
Call the GetChildIndex
and SetChildIndex
methods of the parent's Controls
collection.
There is no Z-order as there was in VB, but you can use the GetChildIndex
and SetChildIndex
methods to get and set their indexes manually.
Here there's an example of how to use it. You will probably need to keep a record of each controls index though so you can set it back to it when it's finished with.
Something like this is probably what you're after:
// Get the controls index
int zIndex = parentControl.Controls.GetChildIndex(textBox);
// Bring it to the front
textBox.BringToFront();
// Do something...
// Then send it back again
parentControl.Controls.SetChildIndex(textBox, zIndex);