|
-
Oct 2nd, 2000, 04:15 PM
#1
Thread Starter
New Member
Does anyone know how to make form so you can drag and drop them accross the desktop without clicking on the blue title bar.
Cheers
-
Oct 2nd, 2000, 04:28 PM
#2
_______
<?>
Option Explicit
Code:
Option Explicit
'Make A Titleless Form Moveable With Mouse Drag
'Add the following code to the declarations section of a form
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 Declare Sub ReleaseCapture Lib "User32" ()
Const WM_NCLBUTTONDOWN = &HA1
Const HTCAPTION = 2
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim lngReturnValue As Long
If Button = 1 Then
Call ReleaseCapture
lngReturnValue = SendMessage(Form1.hWnd, WM_NCLBUTTONDOWN, _
HTCAPTION, 0&)
End If
End Sub
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Oct 2nd, 2000, 04:30 PM
#3
To do it without API:
Code:
Dim oldX As Long, oldY As Long, isMoving As Boolean
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
oldX = X
oldY = Y
isMoving = True
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If isMoving Then
Me.Top = Me.Top - (oldY - Y)
Me.Left = Me.Left - (oldX - X)
End If
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
isMoving = False
End Sub
-
Oct 2nd, 2000, 04:42 PM
#4
Code:
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_SYSCOMMAND = &H112
Private Const SC_MOVE = &HF012
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
ReleaseCapture
SendMessage hwnd, WM_SYSCOMMAND, SC_MOVE, 0
End Sub
-
Oct 2nd, 2000, 04:45 PM
#5
Matthew:
you can shorten your code by disregarding the boolean flag and by using the Move method.
Code:
Dim prevX As Single, prevY As Single
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
prevX = X
prevY = Y
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then Move Left - (prevX - X), Top - (prevY - Y)
End Sub
-
Oct 2nd, 2000, 05:00 PM
#6
Thanks Megatron...nice, short, and it works just the same .
-
Oct 3rd, 2000, 02:32 PM
#7
Thread Starter
New Member
Thanks everyone, the code worked perfectly.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|