MoveFormNoBar (2)




Dim xx, yy as Integer

Public Sub Form_MouseDown(Button as integer, Shift as integer, X as single, Y as single)
xx = X
yy = Y
End Sub

Public Sub Form_MouseMove(Button as integer, Shift as integer, X as single, Y as single)
If Button = 1 Then
form1.Left = X + (form1.left - xx)
form1.top = x + (form1.top - yy)
End If
End Sub
Assumes:
Here are the steps that should be followed for the code
to work properly.

1. Declare two(2) Integer Type variables in the general
declarations section of the form.

Dim xx, yy as Integer

2. Double click on the form and Visual Basic will present
you With an Event procedure that looks like this.

Public Sub Form_click()
End Sub

3. Where are going to use the MouseDown and MouseMove
events, so first choose MouseDown Then MouseMove in
the events list. You will then be given two(2) event
procedures that looks like this.

Public Sub Form_MouseDown(Button as integer, _
Shift as integer, X as single, Y as single)
End Sub

Public Sub Form_MouseMove(Button as integer, _
Shift as integer, X as single, Y as single)
End Sub

4. In the MouseDown event, assign the values of X to one
of your variables and Y to your other variable.

Public Sub Form_MouseDown(Button as integer, _
Shift as integer, X as single, Y as single)
xx = X
yy = Y
End Sub

5. Now the last part, in the MouseMove Event copy the
following code into your MouseMove event procedure.

Public Sub Form_MouseMove(Button as integer, _
Shift as integer, X as single, Y as single)
If Button = 1 Then
form1.Left = X + (form1.left - xx)
form1.top = x + (form1.top - yy)
End If
End Sub

6. Just exchange form1 to the name of the form you are
using and everything will be all right. Start your
program Then move your form around you screen by just
dragging the form itself. No need for the title bar.










( moveformnobar2.html )- by Paolo Puglisi - Modifica del 17/12/2023