Hi,
I want to know how a form can be moved on the MouseDown event, like you can move the form while dragging it, instead of 'finish' dragging it. Just like Winamp. Pls tell me
thanx
Printable View
Hi,
I want to know how a form can be moved on the MouseDown event, like you can move the form while dragging it, instead of 'finish' dragging it. Just like Winamp. Pls tell me
thanx
Try making a boolean value (myBool), and four long values (nX, nY, cX, cY) in the General Declarations. On the MouseDown, set this boolean to true, and nX and nY values to the X and Y. Then, in the mousemove, make cX equal to nX - X, and cY equal to nY - Y. Then set nX to X, and nY to Y. On the MouseUp, set the boolean to false. Here's a bit of code explaining this:After this, you can do basically whatever you want with this code, you could set the form's position, or make a selection rectangle. Lots of things can be accomplished!VB Code:
[COLOR=indigo]Form1.frm[/COLOR] Option Explicit Dim myBool Dim nX As Long Dim nY As Long Dim cX As Long Dim cY As Long Private Sub Form_MouseDown(...) myBool = True nX = X nY = Y End Sub Private Sub Form_MouseMove(...) cX = X - nX cY = Y - nY End Sub Private Sub Form_MouseUp(...) myBool = False End Sub
what does the X and Y stand for and wat ar variables like nY for?
If you clicked, and held and moved your mouse, nX and nY would be the amount it was moved every time. X and Y are the positions of your mouse from the top of the form [or control] and from the left of the form [or control], respectively.
i get what u mean but i still can't get it to work
poor me..
Well the code in itself does nothing! To add functionality... add Me.Move cX, cY after all the other code in the mousemove section.
oh it worked(somehow).....but it turned out funny, all flickering and leaving traces until i release and move my mouse away?
Yeah, it tends to do that. There is a non-buggy windowless move somewhere on the 'net, try to find that.
Cheers from Canada
Sas you should know I have that demo ;)
However, I corrected you that code, try this:
Code:'Variables
Dim X2 As Long
Dim Y2 As Long
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
'Store mouse position
X2 = X
Y2 = Y
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
'Move form if neccessary
If Button = 1 Then: Me.Move Me.Left + (X - X2), Me.Top + (Y - Y2)
End Sub
'Code improved by vBulletin Tool 2.0
True fox, too true =)
thanx and agree
there is a setting in windows to change that...
it makes the form move while you drag it...;)
*sigh* thats not what he meant