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 vertical 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 an up/down 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 bottom PictureBox.

 
Private Const SPLITTER_HEIGHT = 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 hgt1 As Single
Dim hgt2 As Single

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

    hgt1 = (ScaleHeight - SPLITTER_HEIGHT) * Percentage1
    Picture1.Move 0, 0, ScaleWidth, hgt1

    hgt2 = (ScaleHeight - SPLITTER_HEIGHT) - hgt1
    Picture2.Move 0, hgt1 + SPLITTER_HEIGHT, ScaleWidth, _
        hgt2
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 = Y / ScaleHeight
    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