Move a non-caption form using no API, no DLL

By | 2019-09-24

Paste the following code in a module and call it from the mousemove routine of the form that you like to move as: mousemove [form.name],x,y,button.

Drag the form to move it, use same calling code if you need to move the form dragging over a control in the form (pay attention to click_routine potential conflict).

Sub moveform(ff As Form, xx, yy, bt)
    Static oldx, oldy, mf
    Dim moveleft, movetop

    moveleft = ff.Left + xx - oldx
    movetop = ff.Top + yy - oldy
    If bt = vbLeftButton Then
        If mf = 0 Then
            ff.Move moveleft, movetop
            ff.Refresh
            mf = 1
        Else
            mf = 0
        End If
    End If
    oldx = xx
    oldy = yy
End Sub

Usage

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    moveform Me, X, Y, Button
End Sub

Date:2019-09-24

Author: dwirch

Derek Wirch is a seasoned IT professional with an impressive career dating back to 1986. He brings a wealth of knowledge and hands-on experience that is invaluable to those embarking on their journey in the tech industry.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.