How to set Z-order of a Control using WinForms

g t picture g t · Jul 9, 2010 · Viewed 75.3k times · Source

I'm writing a custom TextBox that upon gaining focus changes its border style.

As adding a border causes the control to overlap with those neighbouring it, I temporarily bring the text box to the front of the dialog (using textBox.BringToFront()).

However, once editing is complete and focus is lost, I would like to send the control back to its original position in the Z-order.

Is this possible (preferably in a simple way!)

Answer

SLaks picture SLaks · Jul 9, 2010

Call the GetChildIndex and SetChildIndex methods of the parent's Controls collection.