clearing a transparent panel

  • Thread starter Thread starter Laxmikant Rashinkar
  • Start date Start date
L

Laxmikant Rashinkar

Hi,

I have created a Panel and set its backcolor property to color.transparent.
Because of this, I am able to see the controls behind this panel.

Now, I draw lines on the transparent panel, and I am able to see the lines
as well as the controls behind the transparent panel. This is exactly what I
want.

Now, how do I clear the transparent panel so that the lines I have drawn on
it
dispapper? I have tried using g.Clear(Color.Transparent) and also
g.FillRect(...) with Color.Transparent, but none of them work.

Any input greatly appreciated.

thanks
LK
 
Can you just invalidate the panel, and then not execute the code that paints
the lines when on Paint event/onPaint method fires?
 
I should have mentioned that the reason that I want to clear the old lines,
is that I want to draw new lines after erasing the old lines.
If I invalidate the panel and then not execute the paint event, I will not
be able to draw any new lines.

thank you
LK
 
Not to beat a dead horse too much, but you can still execute the paint
method: just execute the line drawing code conditionally. So, you draw
your old lines, invalidate, then in the paint, you refrain from drawing your
old lines, and draw your new lines.
override protected void OnPaint(args)
{
if(some condition)
DrawFirstSetOfLines;
else
DrawNextSet;
}

Or, if you need something more robust, you could encapsulate the line
drawing logic in an object that describes the lines to draw.

Before you call Invalidate, you'd set the line painter object:
this.LinePainter = someNewLines;
Invalidate()

OnPaint()
{
this.LinePainter.PaintLines()
}

With each set of new set lines to draw, would just use a new linepainter

that same basic pattern could be accomplished with if statements, or
delegates, or whatever.
 
You are right, that would work :)
Thank you so much for taking the time out to reply.
I sure appreciate your help.
 
Back
Top