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
 
 
 
 
 
TitleSend a window to the top or bottom in Visual Basic .NET
DescriptionThis example shows how to send a window to the top or bottom in Visual Basic .NET.
Keywordssend window to bottom, send window to top, to top, to bottom, Visual Basic .NET, VB.NET
CategoriesControls, API
 
The program uses the SetWindowPos API function to move the window to the top or bottom.
 
<DllImport("user32.dll", SetLastError:=True)> _
Private Shared Function SetWindowPos(ByVal hWnd As IntPtr, _
    ByVal hWndInsertAfter As IntPtr, ByVal X As Integer, _
    ByVal Y As Integer, ByVal cx As Integer, ByVal cy As _
    Integer, ByVal uFlags As UInt32) As Boolean
End Function

ReadOnly HWND_BOTTOM As New IntPtr(1)
ReadOnly HWND_TOP As New IntPtr(0)

Private Const SWP_NOSIZE As UInt32 = &H1
Private Const SWP_NOMOVE As UInt32 = &H2

Private Sub btnSendToBottom_Click(ByVal sender As _
    System.Object, ByVal e As System.EventArgs) Handles _
    btnSendToBottom.Click
    Dim flags As UInt32 = SWP_NOMOVE Or SWP_NOSIZE
    SetWindowPos(Me.Handle, HWND_BOTTOM, 0, 0, 0, 0, flags)
End Sub

Private Sub btnBringToTop_Click(ByVal sender As _
    System.Object, ByVal e As System.EventArgs) Handles _
    btnBringToTop.Click
    Dim flags As UInt32 = SWP_NOMOVE Or SWP_NOSIZE
    SetWindowPos(Me.Handle, HWND_TOP, 0, 0, 0, 0, flags)
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated