If you create a form without a caption bar, there is normally no way for the user to move it with a mouse. If you wish to allow the user to move the form with a mouse by dragging on any part of the form, not just the caption, you can use this class to handle the mouse-related events required to make this happen.
Procedure Name | Type | Description |
(Declarations) | Declarations | Declarations and private variables for the CCaptionlessWindowMover class. |
Form | Property | Get a pointer to the form previously assigned. |
Class_Terminate | Terminate | Release storage for local object variables. |
HandleMouseDown | Method | Handle the MouseDown event of the encapsulated form (call from this method from the form's MouseDown event). |
HandleMouseMove | Method | Handle the MouseMove event of the encapsulated form (call from this method from the form's MouseMove event). |
HandleMouseUp | Method | Handle the MouseUp event of the encapsulated form (call from this method from the form's MouseUp event). |
' Example of the CCaptionlessWindowMover class ' ' To try this example, do the following: ' 1. Create a new form ' 2. Paste all the code from this example to the new form's module ' 4. Run the form, and try moving the form around by clicking anywhere on the body of the form and dragging ' In the Declarations section of the form define the variable Private mCaptionlessWindowMover As CCaptionlessWindowMover Private Sub Form_Load() ' Assign a form to the variable Set mCaptionlessWindowMover = New CCaptionlessWindowMover Set mCaptionlessWindowMover.Form = Me End Sub Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, Y As Single) ' Handle the form's MouseDown event mCaptionlessWindowMover.HandleMouseDown x, Y End Sub Private Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, Y As Single) ' Handle the form's MouseMove event mCaptionlessWindowMover.HandleMouseMove x, Y End Sub Private Sub Form_MouseUp(Button As Integer, Shift As Integer, x As Single, Y As Single) ' Handle the form's MouseUp event mCaptionlessWindowMover.HandleMouseUp End Sub
The source code in Total Visual Sourcebook includes modules and classes for Microsoft Access, Visual Basic 6 (VB6), and Visual Basic for Applications (VBA) developers. Easily add this professionally written, tested, and documented royalty-free code into your applications to simplify your application development efforts.
Total Visual SourceBook is written for the needs of a developer using a source code library covering the many challenges you face. Countless developers over the years have told us they learned some or much of their development skills and tricks from our code. You can too!
Supports Access/Office 2016, 2013, 2010 and 2007, and Visual Basic 6.0!
"The code is exactly how I would like to write code and the algorithms used are very efficient and well-documented."
Van T. Dinh, Microsoft MVP