Sign in to follow this  

[.net] Repaint Equivelent

This topic is 4130 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
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
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

This topic is 4130 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this