|
|
Title | Make a resizable toolbox inside a form |
Description | This example shows how to make a resizable toolbox inside a form in Visual Basic 6. It uses drag and drop to let the user move the toolbox. |
Keywords | toolbox, resizable toolbox, PictureBox |
Categories | Controls, Software Engineering |
|
|
(I don't remember who gave me this example, but the code mentions Sandia Software.)
Each toolbox is a make up of a PictureBox containing a caption label and a close button.
The main program uses API functions to give the PictureBoxes resizable borders (WS_THICKFRAME). The user can click and drag on these to resize the PictureBox automatically. When the user resizes the PictureBoxes, the program rearranges its label and button.
|
|
Private Sub Form_Load()
Dim ret%, Style&, i As Integer
For i = 0 To 1
Style& = GetWindowLong(Form1.ToolBox(i).hwnd, _
GWL_STYLE)
Style& = Style& Or WS_THICKFRAME
Style& = SetWindowLong(Form1.ToolBox(i).hwnd, _
GWL_STYLE, Style&)
ret% = SetWindowPos(Form1.ToolBox(i).hwnd, _
Form1.hwnd, 0, 0, 0, 0, SWP_NOZORDER Or _
SWP_NOSIZE Or SWP_NOMOVE Or SWP_DRAWFRAME)
Next i
End Sub
|
|
If you click the button, the program hides its toolbox.
|
|
Private Sub Command1_Click(Index As Integer)
'exit buttons for toolbars
ToolBox(Index).Visible = False
End Sub
|
|
If you press the mouse down on the label, the program starts a drag so you can move the toolbox. The program lets you drop the toolbox on the form.
|
|
Private Sub Label1_MouseDown(Index As Integer, Button As _
Integer, Shift As Integer, X As Single, Y As Single)
Dim i As Integer
'set header highlights
'this highlight needs more work to make it work with
' resize
For i = 0 To 1
If i <> Index Then
Label1(i).BackColor = INACTIVE_TITLE_BAR
End If
Next i
ToolBox_GotFocus (Index)
'set this so when dropped on form, form is in right mode
Form1.ScaleMode = 1
ToolBox(Index).ScaleMode = 1
'drag
DragDownx = (X + Label1(Index).Left)
DragDowny = (Y + Label1(Index).Top)
ToolBox(Index).Drag
End Sub
|
|
|
|
|
|