Send controls to the back or front of the stacking order in C#
A control's SendToBack and BringToFront methods move a control to the back or front of the stacking order. The buttons contained in this program use the following code to move themselves to the front or back of the stacking order.
private void btnToTop_Click(object sender, EventArgs e)You can also use the control's parent's Controls collection's SetChildIndex to change the control's position in the collection. Set the index to 0 for the front of the stacking order. Set it to Controls.Count - 1 for the back of the stacking order. For example, the following code moves the button btn so it is second from the front.
{
Button btn = sender as Button;
btn.BringToFront();
}
private void btnToBottom_Click(object sender, EventArgs e)
{
Button btn = sender as Button;
btn.SendToBack();
}
btn.Parent.Controls.SetChildIndex(btn, 1);


Comments