Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleChange control stacking order at run time in Visual Basic .NET
DescriptionThis example shows how to change control stacking order at run time in Visual Basic .NET.
Keywordsstacking order, zorder, z-order, Visual Basic .NET, VB.NET
CategoriesControls
 
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 Sub btnToTop_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles btnToTop1.Click, _
    btnToTop2.Click
    Dim btn As Button = DirectCast(sender, Button)
    btn.BringToFront()
End Sub

Private Sub btnToBottom_Click(ByVal sender As _
    System.Object, ByVal e As System.EventArgs) Handles _
    btnToBottom1.Click, btnToBottom2.Click
    Dim btn As Button = DirectCast(sender, Button)
    btn.SendToBack()
End Sub
 
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 that invokdes this event handler so it is second from the front.

 
Private Sub btnSecondToTop_Click(ByVal sender As _
    System.Object, ByVal e As System.EventArgs) Handles _
    btnSecondToTop.Click
    Dim btn As Button = DirectCast(sender, Button)
    btn.Parent.Controls.SetChildIndex(btn, 1)
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated