|
-
Oct 12th, 2007, 01:34 PM
#1
Thread Starter
Addicted Member
[2005] Moving the form with a picturebox?
Okay, so just wondering, if its possible. I Have a picturebox (PictureBox1) and just wondering if I dragged the picturebox how could i drag the form?
-
Oct 12th, 2007, 02:52 PM
#2
Re: [2005] Moving the form with a picturebox?
this works
Code:
' Tracks whether the form is in drag mode. If it is, mouse movements
' over the picturebox will be translated into form movements.
Dim Dragging As Boolean
' Stores the offset where the picturebox is clicked.
Dim PointClicked As Point
Private Sub picturebox1_MouseDown(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) Handles picturebox1.MouseDown
If e.Button = MouseButtons.Left Then
Dragging = True
PointClicked = New Point(e.X, e.Y)
Else
Dragging = False
End If
End Sub
Private Sub picturebox1_MouseMove(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) Handles picturebox1.MouseMove
If Dragging Then
Dim PointMoveTo As Point
' Find the current mouse position in screen coordinates.
PointMoveTo = Me.PointToScreen(New Point(e.X, e.Y))
' Compensate for the position the control was clicked.
PointMoveTo.Offset(-PointClicked.X, -PointClicked.Y - (Me.Height - Me.ClientRectangle.Height))
' Move the form.
Me.Location = PointMoveTo
End If
End Sub
Private Sub picturebox1_MouseUp(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) Handles picturebox1.MouseUp
Dragging = False
End Sub
Last edited by .paul.; Oct 12th, 2007 at 03:25 PM.
Reason: improvement
-
Oct 13th, 2007, 05:23 AM
#3
Thread Starter
Addicted Member
Re: [2005] Moving the form with a picturebox?
Thanks! Ill try it now 
EDIT: Thanks so much Ive been trying to do this for ages!
Last edited by Ashylay; Oct 13th, 2007 at 05:26 AM.
-
Sep 20th, 2009, 09:01 PM
#4
Member
Re: [2005] Moving the form with a picturebox?
Hey, thanks .Paul, it worked great for me :-)
-
Dec 26th, 2009, 09:18 PM
#5
Lively Member
Re: [2005] Moving the form with a picturebox?
Don't forget to mark this thread "resolved".
Thank you Paul.
-
Dec 26th, 2009, 10:48 PM
#6
Addicted Member
Re: [2005] Moving the form with a picturebox?
Smaller/Compressed Code (Easy for memorization):
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
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
|