Results 1 to 3 of 3

Thread: [RESOLVED] [2005] Graphic problem when resizing a PictureBox on MouseMove

  1. #1

    Thread Starter
    Hyperactive Member ZaNi's Avatar
    Join Date
    Jun 2006
    Location
    Australia
    Posts
    360

    Resolved [RESOLVED] [2005] Graphic problem when resizing a PictureBox on MouseMove

    I have a picturebox with a background image in it. I have many other pictureboxes on top of the first picturebox. I need to move/resize different pictureboxes based on click & drag type interaction. All the interactions only take place on the X-axis (ie they always stay at the same height).

    The part I'm having trouble with is the picturebox moving is not being drawn properly while the mouse is still held (see attached screenshot). As soon as the mouse is no longer clicked, the picture updates correctly.

    I need a way to avoid the graphical fault it is creating. I don't need to use pictureboxes, but it is a strong preference, as I am using them to handle the click events and make the coordinates easier (as opposed to using one background picturebox and trying to figure out what corrosponds to where the user clicked, then what I have to do in response etc etc).

    Since I don't ask many questions, I can give rep to a good answer here

    EDIT: I've found another problem... This code (should be fairly self-expainatory; e.location is where the mouse is) is producing unpredictable results (the picturebox is moving to odd locations). It is placed in the mouseMove event of the picturebox:
    VB Code:
    1. PB.Location = New Point(initialPoint.X + e.Location.X, PB.Location.Y)

    Description of the attachment: The first half is while the mouse is held, the second half is after the mouse is released. I only moved the picturebox, I didn't resize it. Note the green box in the second half that is missing from the first - that's the problem.
    Attached Images Attached Images  
    Last edited by ZaNi; Aug 13th, 2006 at 09:00 PM.
    * Don't limit yourself to sanity
    * I'd rather be optimistic and naive than pessimistic and right
    * Ask good questions, get good answers.

    My Codebank submissions:
    How to write one rountine to handle many events
    Accessing and Using variables across multiple forms
    Printing/Previewing a form or control

    Links I've "borrowed" from other people:
    vbdotnetboy - Awesome site for tips

  2. #2
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: [2005] Graphic problem when resizing a PictureBox on MouseMove

    Try this
    VB Code:
    1. Private Sub PB_MouseMove(ByVal sender As System.Object, _
    2.         ByVal e As System.Windows.Forms.MouseEventArgs) Handles PB.MouseMove
    3.         Static MouseX As Single
    4.         If e.Button = MouseButtons.Left Then
    5.             PB.Location = New Point(PB.Location.X - MouseX + e.X, PB.Location.Y)
    6.         Else
    7.             MouseX = e.X
    8.         End If
    9.     End Sub

  3. #3

    Thread Starter
    Hyperactive Member ZaNi's Avatar
    Join Date
    Jun 2006
    Location
    Australia
    Posts
    360

    Re: [2005] Graphic problem when resizing a PictureBox on MouseMove

    If I could rate you twice, I would. Thank you very much.
    * Don't limit yourself to sanity
    * I'd rather be optimistic and naive than pessimistic and right
    * Ask good questions, get good answers.

    My Codebank submissions:
    How to write one rountine to handle many events
    Accessing and Using variables across multiple forms
    Printing/Previewing a form or control

    Links I've "borrowed" from other people:
    vbdotnetboy - Awesome site for tips

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