Results 1 to 6 of 6

Thread: [RESOLVED] Drawing Problem, .Update not needed?

  1. #1

    Thread Starter
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

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

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Drawing Problem, .Update not needed?

    Moved From The CodeBank (which is for sharing finished code rather than posting questions )

  3. #3
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    Re: Drawing Problem, .Update not needed?

    Quote Originally Posted by opus View Post
    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

  4. #4

    Thread Starter
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    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!

  5. #5
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,201

    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

  6. #6

    Thread Starter
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: Drawing Problem, .Update not needed?

    Quote Originally Posted by boops boops View Post
    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
  •  



Click Here to Expand Forum to Full Width