Re: OnPaint automatically call e.Graphics.Clear()?
- From: Jesse Houwing <jesse.houwing@xxxxxxxxxxxxxxxx>
- Date: Mon, 23 Apr 2007 20:23:08 +0200
* gilbert@gmail wrote, On 23-4-2007 18:39:
Hello.
I have a question about OnPaint override.
For example, if i have the following code in my inherited form class,
private Brush _brush = Brushes.Black;
private RectangleF _rect = new RectangleF(0,0,100,100);
private int counter =0;
protected override void OnPaint(PaintEventArgs e){
if (counter==0){
counter++;
e.Graphics.Clear(Color.White);
e.Graphics.DrawString("Test", this.Font, _brush, _rect);
}
}
I expect the OnPaint method will do nothing after the first call. That
means, the string "Test" should stay on screen if the form is not
resized/moved/covered by other windows. However, in
reality, the OnPaint do the e.Graphics.Clear() automatically.
I'd like to know if that is possible for me to stop that behavior. In
my application, my form contains many individual text strings. The
strings are updated periodically individually. I would like to render
the updated strings only, not rendering the whole thing for every
string update. Thank you very much for your help!
Gilbert
You can Dubblebuffer the original graphics in a bitmap image and draw that on the graphics surface at the beginning of your paint method.
Jesse
.
- Follow-Ups:
- Re: OnPaint automatically call e.Graphics.Clear()?
- From: gilbert@gmail
- Re: OnPaint automatically call e.Graphics.Clear()?
- References:
- OnPaint automatically call e.Graphics.Clear()?
- From: gilbert@gmail
- OnPaint automatically call e.Graphics.Clear()?
- Prev by Date: RE: DGV CellValidating event not letting new forms be focused
- Next by Date: Windows Form App and VPN
- Previous by thread: OnPaint automatically call e.Graphics.Clear()?
- Next by thread: Re: OnPaint automatically call e.Graphics.Clear()?
- Index(es):
Relevant Pages
|