[RESOLVED] Grab Picturebox to move the form.
A new journey, A new problem.
As I downloaded VS2010 Today, there's a new UI, New Code, new problems.
Now I looked for a code that seemed to work for the VS2008, I found the one .Paul made, but it sure didn't work for me.
Is there anyone who managed this on the new 2010? Please tell me.
If there were any confusion what I really wanted, I'll explain.
Mousedown on Picturebox = Move around the form free.
Thanks :)
Re: Grab Picturebox to move the form.
Code:
Dim Moveable As Boolean
Dim LastPos As Point
Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
Moveable = True
LastPos = Cursor.Position - Me.Location
End Sub
Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
If Moveable Then
Me.Location = Cursor.Position - LastPos
End If
End Sub
Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
Moveable = False
End Sub
Re: Grab Picturebox to move the form.
If you move to fast with that, then it gets kind of glitchy.
You can use an API to do that instead actually. I know this code is used to move forms, but I found out (by mistake) that you can move objects with it too.
vb.net Code:
Private Declare Sub ReleaseCapture Lib "user32" ()
Private Declare Sub SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer)
Private Const WM_NCLBUTTONDOWN As Integer = &HA1
Private Const HTCAPTION As Integer = 2
Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
ReleaseCapture()
SendMessage(PictureBox1.Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0&)
End Sub
Re: Grab Picturebox to move the form.
Thank you for the replies, it worked very well mal1t1a =)
Re: Grab Picturebox to move the form.
Quote:
Originally Posted by
macbrutal
Thank you for the replies, it worked very well mal1t1a =)
Also, it's important to note that you shouldn't be using VS 2010 for actual projects as it is still in BETA. You should only be using it for testing out the new features of the IDE and 4.0 framework.
Re: Grab Picturebox to move the form.
Quote:
Originally Posted by
weirddemon
Also, it's important to note that you shouldn't be using VS 2010 for actual projects as it is still in BETA. You should only be using it for testing out the new features of the IDE and 4.0 framework.
This is very true, it's still highly unstable, even when running on Windows 7. It does happen to have "glitches" in it, that cause it to crash. I have not been able to find a way to properly re-create these events, as they happen randomly, which means I can not submit a proper bug report.
Also, you are welcome macbrutal, glad I could help. =)