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 using only VB
Keywordssplitter, vertical, paned window, sash
CategoriesControls
 
Place two PictureBoxes on the form with a small gap between. When the user clicks and drags on this area, the MouseMove event handler determines how much room to give each PictureBox and rearranges the controls.
 
Private Const SPLITTER_WIDTH = 40

' The percentage occupied by the 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