Clearing the window

  • Thread starter Thread starter James
  • Start date Start date
J

James

Hello,

I'm drawing to the window and want to then clear it to the standard
background colour.
However I get errors when trying either of the following:
Graphics g = CreateGraphics();
g.Clear(Parent.BackColor);
g.FillRectangle(new SolidBrush(Parent.BackColor), 0, 0, 600, 600);

Can anyone please help?

James Round
 
James,

The way that you are going about it is wrong. What you want to do is
override the OnPaint method so that it will draw your shape, or, clear the
panel, based on state that you set in your form.

For example, I would have a boolean field indicating whether or not to
paint the shape or not.

Then, in your OnPaint method (after you call the base method
implementation), you would paint your shape.

Also, you might want to use the using statement when constructing the
Brush. If you don't, then you will leak resources.

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top