[RESOLVED] Drawing Problem, .Update not needed?
I'm trying to follow the technique discribed by jmcilhinney in this
HTML Code:
http://www.vbforums.com/showthread.php?t=426684#post3376040
.
I have all the drawing code in the .Paint event. Reading the above mentioned thread I would need .Invalidate(all or parts of the picturebox) AND .Update() in order to repaint (all or parts of) my PictureBox, however in my case it works without .Update. Am I doing something wrong?
Edit: This wasn't intended as a CodeBank entry, sorry for that.
Re: Drawing Problem, .Update not needed?
Moved From The CodeBank (which is for sharing finished code rather than posting questions :) )
Re: Drawing Problem, .Update not needed?
Quote:
Originally Posted by
opus
I'm trying to follow the technique discribed by jmcilhinney in this
HTML Code:
http://www.vbforums.com/showthread.php?t=426684#post3376040
.
I have all the drawing code in the .Paint event. Reading the above mentioned thread I would need .Invalidate(all or parts of the picturebox) AND .Update() in order to repaint (all or parts of) my PictureBox, however in my case it works without .Update. Am I doing something wrong?
Edit: This wasn't intended as a CodeBank entry, sorry for that.
Invalidate (without Update) says to repaint the invalidated area as soon as there is some processor time free. It's a bit like invoking a separate thread. Update says do it now, before performing any other code.
In many situations it won't make much practical difference whether you use Update or not. There are some situations where it's better not to use it, for example if you are dragging an image with the mouse. Using Update or Refresh in the MouseMove event handler forces the image to be repainted every time the event fires, which can result in a laggy movement. There are other situations where it's better to use Update, for example if you are animating a smooth linear or rotary movement with a timer. Update may also be essential when you have other threads/processing keeping the processor busy.
BB
Re: Drawing Problem, .Update not needed?
Thanks, I was wondering why the picturebox did show the updated image.
I'm not having any problems with smooth movement, my current problem is more like this:
During MouseMove (with Button pressed) as line is drawn with some text to it, this line is drawn from MouseDown-Position to current Mouse Position. All works well besides if I move the mouse real quick, in this case the Rectangle that is given to .Invalidate doesn't contain all the drawn text. I already use a rectangle that is .Enlarged(100,100) and do still observe this effect. However .Enlarging by that much makes the whole process of invalidating only parts quite useless.
Re: Drawing Problem, .Update not needed?
If you are dragging fast, you may find it works best to invalidate the old rectangle first, then the new rectangle. Inflating the rectangle sometimes helps too, but usually I find 1 or 2 pixels all round is enough. Here's an example from my ZoomPictureBox thread in the Code Bank:
Code:
Protected Overrides Sub OnMouseMove(e As System.Windows.Forms.MouseEventArgs)
If _dragging Then
Me.Invalidate(_ImageBounds) 'old position
_ImageBounds.X += e.X - _startDrag.X
_ImageBounds.Y += e.Y - _startDrag.Y
_startDrag = e.Location
Me.Invalidate(_ImageBounds) 'new position
End If
MyBase.OnMouseMove(e)
End Sub
Follow the ZoomPictureBox link below and in particular post #10 for more details.
BB
Re: Drawing Problem, .Update not needed?
Quote:
Originally Posted by
boops boops
If you are dragging fast, you may find it works best to invalidate the old rectangle first, ....
That did help. Sometimes it's the quite obvious what you can't see! Thanks!