Jump to content
  • Advertisement
Sign in to follow this  
eat2thepieseye

[.net] Repaint Equivelent

This topic is 4350 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have been programming java for a few years and I have recently decided to learn a few more languages (C# is one of them). I have an Application in C# where one of the lines is "this.Paint += new PaintEventHandler(PaintEvent);" and I have a method void PaintEvent(object sender, PaintEventArgs e) which handles the paint events. Right now this method is only called at the start of the Application and when the Application leaves the screen and returns to the screen (Minimizing/Window in front of app). How can I call this method at various times in the program?

Share this post


Link to post
Share on other sites
Advertisement
call (for example, in your Size event):

Invalidate();
Update();

they send the paint event. also not you don't have to add your own Paint event, you can just override the virtual OnPaint method.

Share this post


Link to post
Share on other sites
Invalidate and Refresh have overloads that allow you to specify the rectangle (subsection) that needs to be (re)painted. The Paint event receives this area and thus can repaint just the part that has been destroyed. Take care however that you might need to change the style (Setstyle) of the control to prevent the automatic clear of the entire control.

Cheers

Share this post


Link to post
Share on other sites
Quote:
Original post by eat2thepieseye
Thanks. Thats exactly what I needed. One more question though. Is there a way to only update a portion of the screen?


With Invalidate() method you can also specify the portion of the screen you want to be updated by using a Rectangle or a Region.

Share this post


Link to post
Share on other sites
When you call Invalidate then Update, the rectangle/region specified turns to the background color/image before being painted over, resulting in a flash effect. Is there a way for the screen not to be cleared before painting so that this effect does not occur?

Share this post


Link to post
Share on other sites
Yes, that is what I said before: use Setstyle to change that behaviour.

BTW: calling Invalidate AND Refresh is one too much. Refresh forces an update while Invalidate allows the system to pick a time when to redraw.

Cheers

Share this post


Link to post
Share on other sites
OMG. It works perfectly. Thank you so much. Just curious though, how does it work and is there any reason someone would choose not to use this?

[Edited by - eat2thepieseye on January 2, 2007 2:33:09 PM]

Share this post


Link to post
Share on other sites
Sometimes it is just harder to repaint a part than to redraw the entire control.

"but how does it work"

What exactly do you want to know?

Cheers

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!