[Solved] Clearing control of graphics before painting [modified]
-
I have a class called CardHolder which extends UserControl. I have overrode its OnPaint function like so:
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Graphics g = e.Graphics; foreach (Card c in this.Controls) { g.DrawImage(c.Image, c.Location); } }
Each image is tied to a Control which has been added to this control. Each image is a partially transparent image which is partially overlaid another image. However, each time the OnPaint function is called, it doesn't clear the Control of what was there before: Good: http://img20.imageshack.us/i/goodw.jpg/[^] Oh dear: http://img24.imageshack.us/i/ohdearz.jpg/[^] I've hooked into the CardHolder's Resize event and call PositionCards in that function to position the Controls, which in turn calls OnPaint behind the scenes. I hope what I'm doing here makes sense to you guys. How do I clear the Control of the previously drawn images? Card extends UserControl as well but is transparent and has no child controls.modified on Tuesday, July 21, 2009 12:36 PM
-
I have a class called CardHolder which extends UserControl. I have overrode its OnPaint function like so:
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Graphics g = e.Graphics; foreach (Card c in this.Controls) { g.DrawImage(c.Image, c.Location); } }
Each image is tied to a Control which has been added to this control. Each image is a partially transparent image which is partially overlaid another image. However, each time the OnPaint function is called, it doesn't clear the Control of what was there before: Good: http://img20.imageshack.us/i/goodw.jpg/[^] Oh dear: http://img24.imageshack.us/i/ohdearz.jpg/[^] I've hooked into the CardHolder's Resize event and call PositionCards in that function to position the Controls, which in turn calls OnPaint behind the scenes. I hope what I'm doing here makes sense to you guys. How do I clear the Control of the previously drawn images? Card extends UserControl as well but is transparent and has no child controls.modified on Tuesday, July 21, 2009 12:36 PM
How is the
OnPaint
being called? Call theRefresh()
method to make your control invalidate the graphic and repaint itself.
Panic, Chaos, Destruction. My work here is done.
-
How is the
OnPaint
being called? Call theRefresh()
method to make your control invalidate the graphic and repaint itself.
Panic, Chaos, Destruction. My work here is done.