|
-
Mar 29th, 2012, 06:49 AM
#1
[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.
Last edited by opus; Mar 29th, 2012 at 08:03 AM.
Reason: .Me = Stupid while posting in wrong Section
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
-
Mar 29th, 2012, 07:15 AM
#2
Re: Drawing Problem, .Update not needed?
Moved From The CodeBank (which is for sharing finished code rather than posting questions )
-
Mar 29th, 2012, 09:35 AM
#3
Re: Drawing Problem, .Update not needed?
 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
-
Mar 29th, 2012, 10:40 AM
#4
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.
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
-
Mar 29th, 2012, 02:57 PM
#5
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
-
Mar 29th, 2012, 03:56 PM
#6
Re: Drawing Problem, .Update not needed?
 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!
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
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
|