[.net] Repaint Equivelent

Started by
7 comments, last by ernow 17 years, 7 months ago
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?
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.
Thanks. Thats exactly what I needed. One more question though. Is there a way to only update a portion of the screen?
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
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.
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?
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
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]
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

This topic is closed to new replies.

Advertisement