Results 1 to 6 of 6

Thread: [RESOLVED] Grab Picturebox to move the form.

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2008
    Posts
    91

    Resolved [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

  2. #2
    Addicted Member Mal1t1a's Avatar
    Join Date
    Mar 2008
    Posts
    157

    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

  3. #3

    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:
    1. Private Declare Sub ReleaseCapture Lib "user32" ()
    2.     Private Declare Sub SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer)
    3.     Private Const WM_NCLBUTTONDOWN As Integer = &HA1
    4.     Private Const HTCAPTION As Integer = 2
    5.  
    6. Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
    7.         ReleaseCapture()
    8.         SendMessage(PictureBox1.Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0&)
    9.     End Sub

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Feb 2008
    Posts
    91

    Re: Grab Picturebox to move the form.

    Thank you for the replies, it worked very well mal1t1a =)

  5. #5
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: Grab Picturebox to move the form.

    Quote Originally Posted by macbrutal View Post
    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.
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  6. #6
    Addicted Member Mal1t1a's Avatar
    Join Date
    Mar 2008
    Posts
    157

    Thumbs up Re: Grab Picturebox to move the form.

    Quote Originally Posted by weirddemon View Post
    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. =)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width