1 Attachment(s)
[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:
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.
Re: [2005] Graphic problem when resizing a PictureBox on MouseMove
Try this
VB Code:
Private Sub PB_MouseMove(ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) Handles PB.MouseMove
Static MouseX As Single
If e.Button = MouseButtons.Left Then
PB.Location = New Point(PB.Location.X - MouseX + e.X, PB.Location.Y)
Else
MouseX = e.X
End If
End Sub
Re: [2005] Graphic problem when resizing a PictureBox on MouseMove
If I could rate you twice, I would. Thank you very much.