|
-
Oct 10th, 2002, 01:53 PM
#1
Thread Starter
Fanatic Member
Making a form moveable
I know you can make a form moveable by setting moveable to true. However if you make the control box property false and delete the caption then at runtime you cant make the form moveable is there a way I can make a form moveable through code?
Walter Richardson
Striver2000 Christian Productions
Iam seventeen but since I started VB in June of 01 GOD has been helping me excell by finding this great forum with a bunch of GREAT PEOPLE!
-
Oct 10th, 2002, 01:57 PM
#2
PowerPoster
Here's what's involved:
VB Code:
Option Explicit
Public Const WM_NCLBUTTONDOWN = &HA1
Private Const HTCAPTION = 2
Public Declare Function ReleaseCapture Lib "user32" () As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Sub DragForm(frm As Form)
'=================================
On Local Error Resume Next
Call ReleaseCapture
Call SendMessage(frm.hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0)
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
'================================================
If Button = vbLeftButton Then
Call DragForm(Me)
End If
End Sub
-
Oct 10th, 2002, 01:59 PM
#3
Fanatic Member
Re: Making a form moveable
I'm not sure, but I think you can simply use the
With (Form)
.Top
.Left
End With
To modify the position...
Originally posted by Walter100
I know you can make a form moveable by setting moveable to true. However if you make the control box property false and delete the caption then at runtime you cant make the form moveable is there a way I can make a form moveable through code?
-
Oct 10th, 2002, 02:02 PM
#4
So Unbanned
A simple way is:
public mX, mY
in the mousemove event:
if button = 1 then move left+x-mx, top+y-my
in the mousedown event
mx = x
my = y
-
Oct 10th, 2002, 02:03 PM
#5
Thread Starter
Fanatic Member
I inserted the code into a new project and received errors
Walter Richardson
Striver2000 Christian Productions
Iam seventeen but since I started VB in June of 01 GOD has been helping me excell by finding this great forum with a bunch of GREAT PEOPLE!
-
Oct 10th, 2002, 02:04 PM
#6
So Unbanned
-
Oct 10th, 2002, 02:06 PM
#7
PowerPoster
Change all Public declarations to Private and run it.
-
Oct 10th, 2002, 02:06 PM
#8
Thread Starter
Fanatic Member
never mind I have gotten it to work thanks everyone
Walter Richardson
Striver2000 Christian Productions
Iam seventeen but since I started VB in June of 01 GOD has been helping me excell by finding this great forum with a bunch of GREAT PEOPLE!
-
Oct 10th, 2002, 02:07 PM
#9
Thread Starter
Fanatic Member
Yours works digital error thanks
Walter Richardson
Striver2000 Christian Productions
Iam seventeen but since I started VB in June of 01 GOD has been helping me excell by finding this great forum with a bunch of GREAT PEOPLE!
-
Oct 10th, 2002, 02:09 PM
#10
So Unbanned
-
Oct 10th, 2002, 06:38 PM
#11
Software Eng.
Try
Code:
Dim OldX As Single
Dim OldY As Single
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
OldX = X
OldY = Y
End If
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then Move Left + (X - OldX), Top + (Y - OldY)
End Sub
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
|