Re: OnPaint automatically call e.Graphics.Clear()?



* 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
.



Relevant Pages

  • OnPaint automatically call e.Graphics.Clear()?
    ... private Brush _brush = Brushes.Black; ... I expect the OnPaint method will do nothing after the first call. ... my form contains many individual text strings. ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: Find The Text :-)
    ... personally I would suggest writing your own "wrap" code anyway because you will get much more control that way and much more flexibility, including the ability to do things that the DrawText API cannot do. ... If you don't fancy writing the "wrap" code yourself then a very simple alternative would be to use a borderless standard VB TextBox Control and set its size to the same as your required "wrap rectangle" and just dump your string into its Text property. ... You can then send it an EM_GETLINECOUNT to count the number of wrapped lines and EM_GETLINE messages to get those lines into a VB array of Strings. ... Private Declare Function SendMessage Lib "user32" _ ...
    (microsoft.public.vb.general.discussion)
  • Re: OnPaint automatically call e.Graphics.Clear()?
    ... what I have done is creating a Bitmap and draw graphic to the bitmap. ... OnPaint simply calls DrawImage. ... my form contains many individual text strings. ... You can Dubblebuffer the original graphics in a bitmap image and draw ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: How to call HTML (with POST) page from Web form
    ... private mshtml.HTMLDocument ieDoc; ... //use the following for getting at HTML in the document. ... You can see I've wrapped the IE Navigate method just to check for null ... strings and other validations. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Rendering a font
    ... > the strings must fillthe entire screen (Therefore I must strech the fonts ... Derive a new font based on the new scaling ... > private String _sampleString; ... > private int _scaledWidth; ...
    (comp.lang.java.gui)