Results 1 to 4 of 4

Thread: Frames Per Second in Picturebox repaint

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2010
    Posts
    121

    Question Frames Per Second in Picturebox repaint

    Hey guys,

    Been a while since I've been on here, but I need some help. I'm looking for a way to limit Picturebox repaints. For example, I wish to be able to only call "repaint" a certain amount of times per second. All my searchs have come up with nothing. I could start a timer and get it to call repaint manually but that only ends up calling it more as it doesn't stop the normal form raising the event.

    Thanks for any pointers

    -jD
    If I helped you, don't forget to Rate my Post

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,102

    Re: Frames Per Second in Picturebox repaint

    You can't stop the form from raising Paint, nor would you want to. The results of such an action would be hideous (ghosting, blank screens, and other fun visual effects). If you have custom code that you don't want to have run EVERY time the Paint event is raised, then it is that specific problem you need to deal with, not the Paint event itself. For instance, you could do something as simple as this:

    If paintMe Then
    paintMe = False
    'Your code here
    End If

    Put something like that in the Paint event, with paintMe being a form level variable, and your custom painting code will only be run when paintMe is True. Since paintMe is immediately set to False as the first line in the code, the code will only run when YOU set paintMe true, so you can control when the paint code runs. You could add a timer that sets paintMe true only periodically, or you might have a more dynamic solution for when you want the code to run.
    My usual boring signature: Nothing

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Apr 2010
    Posts
    121

    Re: Frames Per Second in Picturebox repaint

    Thanks, I understand where you coming from on the idea of the paint event. Although you solution does seem quite appealing I was wondering a few things. First of all, if I set PaintMe to true say, 10 times a second (10fps) then does it retain the previous buffer on repaint. Because as you said I have a whole stack of lines, dots etc. being painted in the OnPaint event of a picturebox, because the form would be repainting 100 times more than my variable is being set, would the previous buffer be carried to the system raised Paint event? Or would it only appear every time I set PaintMe to true?

    Thanks, -jD
    If I helped you, don't forget to Rate my Post

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,102

    Re: Frames Per Second in Picturebox repaint

    There is no buffer. When you paint, you paint. This is an issue, depending on how you are doing things. Suppose you had a picturebox, the picturebox has an image which you can paint to, so the image would act like the buffer you mention. Just because you do paint one time and don't paint a different time, the image is still the image the times you don't paint. It would kind of suck if the image went away from a picturebox every time you painted. However, if you have some other control, such as a panel, and you are just painting on it, if you don't paint, then the thing is blank. The reason for painting so often is for things such as one window being dragged over another window. The part of the screen where the back window was being displayed is now showing the other window, if that window is dragged further so that it reveals the background window, the foreground window probably lacks enough information to draw the background, so let the background re-draw itself. In the case of the picturebox, what it redraws is the image for the picturebox, but in the case of the panel, it just redraws the panel...which is blank, unless you draw something else on it.
    My usual boring signature: Nothing

Tags for this Thread

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