From: JezzzMoore on
Hey,

Could anyone give me the code to do this?
Ive been trying for weeks to make a form with no window border movable.

Thanks!
From: Norm Cook on
"JezzzMoore" <JezzzMoore(a)discussions.microsoft.com> wrote in message
news:9952D2BA-C80B-4983-A704-04A677A2DBA0(a)microsoft.com...
> Hey,
>
> Could anyone give me the code to do this?
> Ive been trying for weeks to make a form with no window border movable.
>
> Thanks!

Two ways to go.

'Method 1 - simple math
Private PosInFrmX As Long
Private PosInFrmY As Long
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single,
Y As Single)
PosInFrmX = X
PosInFrmY = Y 'position in the form
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single,
Y As Single)
If Button = vbLeftButton Then
Me.Move Me.Left + X - PosInFrmX, Me.Top + Y - PosInFrmY
End If
End Sub


Method2: API (watch for wordwrap)
'note this method will display an empty selection rectangle for the form
while dragging
' unless you have windows set up to show window content while dragging
' For XP this is Control Panel|System|Advanced||Performance
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA"
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As
Any) As Long
Private Const WM_NCLBUTTONDOWN = &HA1
Private Const HTCAPTION As Long = 2

Sub FormDrag(TheForm As Form)
Call ReleaseCapture
Call SendMessage(TheForm.hwnd, WM_NCLBUTTONDOWN, HTCAPTION, ByVal 0&)
End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single,
Y As Single)
FormDrag Me
End Sub