Make your own free website on Tripod.com

Make A Resizer Bar Between Two Controls

'Add 1 Command Button 1 List Box and 1 Text Box to your form.
'You can use this code with other controls. Replace all the appearance of Text1 and
'List1 in this code with your controls name.
'Insert the following code to your form:

Private Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Dim Dragging As Boolean
Dim Z As POINTAPI
Dim TotalWidth

Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Dragging = True
End Sub

Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
If Not Dragging Then Exit Sub
GetCursorPos Z
mypos = Z.x - Form1.Left \ Screen.TwipsPerPixelX - Command1.Width \ 2
If (mypos - Text1.Left <= 20) Or (mypos >= TotalWidth - 20) Then Exit Sub
Command1.Left = mypos
Text1.Width = Command1.Left - Text1.Left
List1.Move Command1.Left + Command1.Width, List1.Top, TotalWidth - Text1.Width
End Sub

Private Sub Command1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
Dragging = False
End Sub

Private Sub Form_Load()
Dragging = False
Text1.Top = 100
Command1.Top = 100
List1.Top = 100
Command1.Height = Text1.Height
List1.Height = Text1.Height
Command1.Left = Text1.Left + Text1.Width
List1.Left = Command1.Left + Command1.Width
TotalWidth = List1.Width + Text1.Width
Command1.Caption = ""
End Sub

Go Back