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
 
 
 
 
 
 
TitleCreate a horizontal splitter (paned window) using only VB
Keywordssplitter, paned window, sash
CategoriesControls
 
Place two PictureBoxes on the form separated by a small distance. Set the form's MousePointer to a left/right arrow so the user sees it when the mouse is over this area between the panes.

When the user clicks and drags on the form, make the form's event handlers adjust the sizes of the PictureBoxes and the position of the right PictureBox.

 
Private Const SPLITTER_WIDTH = 40

' The percentage occupied by the first PictureBox.
Private Percentage1 As Single

' True when we are dragging the splitter.
Private Dragging As Boolean

' Arrange the controls on the form.
Private Sub ArrangeControls()
Dim wid1 As Single
Dim wid2 As Single

    ' Don't bother if we're iconized.
    If WindowState = vbMinimized Then Exit Sub

    wid1 = (ScaleWidth - SPLITTER_WIDTH) * Percentage1
    Picture1.Move 0, 0, wid1, ScaleHeight

    wid2 = (ScaleWidth - SPLITTER_WIDTH) - wid1
    Picture2.Move wid1 + SPLITTER_WIDTH, 0, wid2, _
        ScaleHeight
End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As _
    Integer, X As Single, Y As Single)
    Dragging = True
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As _
    Integer, X As Single, Y As Single)
    If Not Dragging Then Exit Sub

    Percentage1 = X / ScaleWidth
    If Percentage1 < 0 Then Percentage1 = 0
    If Percentage1 > 1 Then Percentage1 = 1
    ArrangeControls
End Sub

Private Sub Form_MouseUp(Button As Integer, Shift As _
    Integer, X As Single, Y As Single)
    Dragging = False
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated