I work on a data acquisition system. I need to display data as it comes.
There are two different modes: 1. Display only current set of data each time
it is ready. 2. Display the current data, but don't erase the previous one.
I remember in MFC I was able to do this by changing one parameter
(DrawBackground() or something like that). I am trying to do it with C# and
failing.
If I use Invalidate() or Invalidate(rect) functions, than the previous data
is erased. However if I just use my plotting functions directly to display
the data, then I need to create Graphics (this.CreateGraphics) and pass it to
the plotting routine. But then the program crashes some time when I try to
resize the window for example. It tells me that a Brush (or Color, etc...) is
used somewhere.

I think it is because I have two requests for plotting data with two
different Graphics: one is coming from acquisition board when the data is
ready, and the other - from Windows when I resize the window.

Is there any way to use Invalidate() but somehow specify not to erase the
background? This would solve all the problems as I did not have to create
another Graphics and just use the one that is generated by .NET in the Paint
message.

Thank you in advance,
Viktor

Re: Invalidate but do not draw background by Bob

Bob
Fri Feb 18 13:29:51 CST 2005

You can override the OnPaintBackground method to do nothing and always
handle bakground painting according to valid / invalid rects.

You can set the style AllPaintingInWmPaint which enables you to selectively
paint the background if you wish.

You should not paint anything using GetGraphics. This breaks the rules of
message-based architecture and causes problems. See the various entries in
the GDI+ FAQ for why.


--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.





"Viktor" <Viktor@discussions.microsoft.com> wrote in message
news:ECBEAC26-56DD-482F-906A-3B975B1B4426@microsoft.com...
>I work on a data acquisition system. I need to display data as it comes.
> There are two different modes: 1. Display only current set of data each
> time
> it is ready. 2. Display the current data, but don't erase the previous
> one.
> I remember in MFC I was able to do this by changing one parameter
> (DrawBackground() or something like that). I am trying to do it with C#
> and
> failing.
> If I use Invalidate() or Invalidate(rect) functions, than the previous
> data
> is erased. However if I just use my plotting functions directly to display
> the data, then I need to create Graphics (this.CreateGraphics) and pass it
> to
> the plotting routine. But then the program crashes some time when I try to
> resize the window for example. It tells me that a Brush (or Color, etc...)
> is
> used somewhere.
>
> I think it is because I have two requests for plotting data with two
> different Graphics: one is coming from acquisition board when the data is
> ready, and the other - from Windows when I resize the window.
>
> Is there any way to use Invalidate() but somehow specify not to erase the
> background? This would solve all the problems as I did not have to create
> another Graphics and just use the one that is generated by .NET in the
> Paint
> message.
>
> Thank you in advance,
> Viktor



Re: Invalidate but do not draw background by Viktor

Viktor
Fri Feb 18 14:05:04 CST 2005

Thank you very much indeed. I new that I had to override something but did
not know what and could not find the function.

You advise helped me and now I have a perfect control.

Viktor

"Bob Powell [MVP]" wrote:

> You can override the OnPaintBackground method to do nothing and always
> handle bakground painting according to valid / invalid rects.
>
> You can set the style AllPaintingInWmPaint which enables you to selectively
> paint the background if you wish.
>
> You should not paint anything using GetGraphics. This breaks the rules of
> message-based architecture and causes problems. See the various entries in
> the GDI+ FAQ for why.
>
>
> --
> Bob Powell [MVP]
> Visual C#, System.Drawing
>
> Find great Windows Forms articles in Windows Forms Tips and Tricks
> http://www.bobpowell.net/tipstricks.htm
>
> Answer those GDI+ questions with the GDI+ FAQ
> http://www.bobpowell.net/faqmain.htm
>
> All new articles provide code in C# and VB.NET.
> Subscribe to the RSS feeds provided and never miss a new article.
>
>
>
>
>
> "Viktor" <Viktor@discussions.microsoft.com> wrote in message
> news:ECBEAC26-56DD-482F-906A-3B975B1B4426@microsoft.com...
> >I work on a data acquisition system. I need to display data as it comes.
> > There are two different modes: 1. Display only current set of data each
> > time
> > it is ready. 2. Display the current data, but don't erase the previous
> > one.
> > I remember in MFC I was able to do this by changing one parameter
> > (DrawBackground() or something like that). I am trying to do it with C#
> > and
> > failing.
> > If I use Invalidate() or Invalidate(rect) functions, than the previous
> > data
> > is erased. However if I just use my plotting functions directly to display
> > the data, then I need to create Graphics (this.CreateGraphics) and pass it
> > to
> > the plotting routine. But then the program crashes some time when I try to
> > resize the window for example. It tells me that a Brush (or Color, etc...)
> > is
> > used somewhere.
> >
> > I think it is because I have two requests for plotting data with two
> > different Graphics: one is coming from acquisition board when the data is
> > ready, and the other - from Windows when I resize the window.
> >
> > Is there any way to use Invalidate() but somehow specify not to erase the
> > background? This would solve all the problems as I did not have to create
> > another Graphics and just use the one that is generated by .NET in the
> > Paint
> > message.
> >
> > Thank you in advance,
> > Viktor
>
>
>