Highlights
All Snippets
Top 100 Snippets
Librarians
gbCodeLib

By Language
VB6
JavaScript
Perl
HTML
SQL
Java
DOS

GBIC >> Source Code >> Visual Basic >> Snippet

Splitter, horizontal (splitter bar)


'the horizontal splitter Is a picturebox called picSplitter. It separate the Left/Right sides of the form
'splitting Is also limited to within the LeftMargin And RightMargin
'when form Is resized, the horizontal Split (on a percentage basis) Is maintained)

'declarations
Dim XPercent As Single
Dim LMargin As Single
Dim RMargin As Single

'on form_load
LMargin = 0
RMargin = 2 * picSplitter.Width
XPercent = 0.5

Private Sub picSplitter_MouseMove(Button As Integer , Shift As Integer , X As Single , Y As Single )
picSplitter.MousePointer = 9
If Button = vbLeftButton Then
    If picSplitter.Left + X > LMargin And picSplitter.Left + X < Width - RMargin Then
       picSplitter.Left = picSplitter.Left + X
       XPercent = picSplitter.Left / Width
        If XPercent > 1 Then XPercent = 1
        If XPercent < 0 Then XPercent = 0
       ArrangeControls
    End If
End If
End Sub

Private Sub Form_Resize()
    If XPercent * Width < RMargin Then XPercent = RMargin / Width
    If (1 - XPercent) * Width < LMargin Then XPercent = 1 - LMargin / Width
   picSplitter.Left = (1 - XPercent) * Width
   ArrangeControls
End Sub

Private Sub ArrangeControls()
Dim width1 As Single     'picture1 Width
Dim width2 As Single     'picture2 Width
    If WindowState = vbMinimized Then Exit Sub    'Do nothing if minimized
   Picture1.Move 0, 0, Width * XPercent, ScaleHeight
   Picture2.Move Width * XPercent + 100, 0, Width * (1 - XPercent), ScaleHeight
End Sub