Printable Version of Topic

Click here to view this topic in its original format

UtterAccess Forums _ Access Code Archive _ Moving a none borderstyle form with the mouse

Posted by: Ernesto Jan 10 2006, 08:19 PM

This is the way I've found for moving a form with the mouse, when the form borderstyle property is set to none. Of course, the moveable property of the form must be set in yes.
form with none borderstyle doesn't have a 'control box' (which usually contains the min, max and close buttons, the title bar, and that let us move the form just left clicking with the mouse), but itīs possible to 'substitute' it with the use of other objects (as a rectangle, a line, an image or other form objects) and its mousedown event or click event.
In a form view, that 'substitution' will allow us to:
1) Select the form with the mouse from its actual position in the screen
2) Drag the form to the next position in the screen
In the code, in the form object mousedown event or click event, we have to use the sendkeys instruction and the DoCmd object with the runcommand method, as follows:
Private Sub rectangle1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = acLeftButton Then
'using both sendkeys instructions we avoid a little displacement of the form
SendKeys "{UP}"
SendKeys "{DOWN}"
'the four-headed arrow will indicate that we could drag the form
Screen.MousePointer = 3
DoCmd.RunCommand acCmdDocMove
'once we drop the form, the pointer will return to its original look
Screen.MousePointer = 0
End If
End Sub
Using the same code with the click event, causes that the form remains attached with the mouse pointer until we do another click.
The code has been proved in access 2000 and access xp, and it worked fine.
I hope this solution could be useful for those who are begining with access, or don't know how to do it.
If someone knows a more simple solution, please let me know it.
Ernesto

 MoveNoneBorderForm.zip ( 31.27K ): 388
 

Posted by: Cyberjudge Sep 23 2019, 08:48 PM

Thank you

Posted by: isladogs Sep 23 2019, 11:13 PM

This is certainly an ancient thread resurrected. from the dead.
A borderless form can be dragged to a new position using a MouseDown event without using SendKeys.

Place the following in a standard module

CODE
Option Compare Database
Option Explicit

'API to move a form with a mouse down event

Public Const WM_NCLBUTTONDOWN = &HA1

Public Const HT_CAPTION = &H2

#If VBA7 Then
    Public Declare PtrSafe Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As LongPtr, _
        ByVal wMsg As Long, ByVal wParam As LongPtr, lParam As Any) As LongPtr
    
    Public Declare PtrSafe Function ReleaseCapture Lib "user32.dll" () As Long
#Else
    Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, _
        ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    
    Public Declare Function ReleaseCapture Lib "user32.dll" () As Long
#End If


Then in your form add code like this to any part of the form you want to control dragging.
For example, using the Form header

CODE
Private Sub FormHeader_MouseDown(B
utton As Integer, Shift As Integer, X As Single, Y As Single)
   X = ReleaseCapture()
   X = SendMessage(Me.hWnd, WM_NCLBUTTONDOWN, HT_CAPTION, 0)
End Sub


The same code can also be applied to other objects such as a button or label

The attached example includes this feature and much more

You can find more information about this example application here http://www.mendipdatasystems.co.UK/control-application-interface/4594365418

 SetWindows___v3.44.zip ( 311.82K ): 28