开发者

What should I do to clear everything I have drawn before drawing new things on custom control?

I have drawn Image on a custom control.

But whenever I draw another Image in the custom control it overwrites or draws over it.Can I clear everything I have drawn, before drawing new things?

MY SOLUTIONS THAT DIDNT WORKED:

S1> I used this.Invalidate() which calls the paint event but it is not solving the problem because I already have some code in it which leads to same overdrawing problem.

S2> Using Clear m开发者_C百科ethod of Graphics class solved the problem. I am using this code to clear everything in my custom control

//in my custom controls paint method
    Graphics g = this.CreateGraphics();
    g.Clear(this.ForeColor);

but it is flickering a lot!Thats why I used DoubleBuffered property and now its not showing anything!


The flickering problem has now been solved. Actually the problem was with the way I created Graphics object.I used this code to create Graphics object:

Graphics g = this.CreateGraphics();

This caused not only flickering problem but also DoubleBuffered property was also not working.

We must actually use Paint event's e.Graphics to create Graphics object and then draw.

Thus, now my DoubleBuffered property is doing its job..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜