Board index » cppbuilder » Clear a form

Clear a form


2005-08-24 10:46:13 AM
cppbuilder73
How do I clear text and or graphics from a form.
Form1->Canvas->Refresh(); does not seem to
work.
TIA Mick.
 
 

Re:Clear a form

"Michael Harrington" < XXXX@XXXXX.COM >wrote in message
Quote
How do I clear text and or graphics from a form.
That depends on what kind of components you put on the form to begin with.
There is no single method to clear everything in one operation. Every
component has its own individual way to clear its particular contents.
Gambit
 

Re:Clear a form

"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote

"Michael Harrington" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...

>How do I clear text and or graphics from a form.

That depends on what kind of components you put on the form to begin with.
There is no single method to clear everything in one operation. Every
component has its own individual way to clear its particular contents.


Gambit

Thanks Remy. I have a button which when pressed draws
some lines and text on Form1. I want to put code into a second
button that erases the lines and text but leaves the buttons in place.
TIA Mick.
 

{smallsort}

Re:Clear a form

"Michael Harrington" < XXXX@XXXXX.COM >wrote in message
Quote
I have a button which when pressed draws some lines and text
on Form1. I want to put code into a second button that erases
the lines and text but leaves the buttons in place.
You did not say how you are drawing the lines and text.
If you are drawing directly on the form's Canvas, then the drawing is only
valid until the form repaints itself. For persistent drawings, you should
be using the form's OnPaint event, in which case your buttons can simpy set
the flag somewhere that the OnPaint code can check when deciding whether to
re-draw the lines and text.
If, on the other hand, you are using components to handle the lines and
text, then as I mentioned earlier each individual component has its own way
of clearing its contents, so again it depends on what exactly you are using
to begin with.
Please provide more details.
Gambit
 

Re:Clear a form

"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote

"Michael Harrington" < XXXX@XXXXX.COM >wrote in message
news: XXXX@XXXXX.COM ...

>I have a button which when pressed draws some lines and text
>on Form1. I want to put code into a second button that erases
>the lines and text but leaves the buttons in place.

You did not say how you are drawing the lines and text.

If you are drawing directly on the form's Canvas, then the drawing is only
valid until the form repaints itself. For persistent drawings, you should
be using the form's OnPaint event, in which case your buttons can simpy
set
the flag somewhere that the OnPaint code can check when deciding whether
to
re-draw the lines and text.

If, on the other hand, you are using components to handle the lines and
text, then as I mentioned earlier each individual component has its own
way
of clearing its contents, so again it depends on what exactly you are
using
to begin with.

Please provide more details.


Gambit

Thanks Remy. Am using......
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Form1->Canvas->TextOutA(200,200,"Hello World");
}
How Do I clear the text?
 

Re:Clear a form

"Michael Harrington" < XXXX@XXXXX.COM >wrote in message
Quote

"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
news:430c2c87$ XXXX@XXXXX.COM ...
>
>"Michael Harrington" < XXXX@XXXXX.COM >wrote in message
>news: XXXX@XXXXX.COM ...
>
>>I have a button which when pressed draws some lines and text
>>on Form1. I want to put code into a second button that erases
>>the lines and text but leaves the buttons in place.
>
>You did not say how you are drawing the lines and text.
>
>If you are drawing directly on the form's Canvas, then the drawing is
>only
>valid until the form repaints itself. For persistent drawings, you
>should
>be using the form's OnPaint event, in which case your buttons can simpy
>set
>the flag somewhere that the OnPaint code can check when deciding whether
>to
>re-draw the lines and text.
>
>If, on the other hand, you are using components to handle the lines and
>text, then as I mentioned earlier each individual component has its own
>way
>of clearing its contents, so again it depends on what exactly you are
>using
>to begin with.
>
>Please provide more details.
>
>
>Gambit
>
Thanks Remy. Am using......

void __fastcall TForm1::Button1Click(TObject *Sender)
{

Form1->Canvas->TextOutA(200,200,"Hello World");
}

How Do I clear the text?
Stumbled across it..
Form1->Repaint();
 

Re:Clear a form

"Michael Harrington" < XXXX@XXXXX.COM >wrote:
Quote
>Am using......
>
>void __fastcall TForm1::Button1Click(TObject *Sender)
>{
>
>Form1->Canvas->TextOutA(200,200,"Hello World");
>}
>
>How Do I clear the text?

Stumbled across it..
Form1->Repaint();
Hm, I guess you havn't understood completely yet what Remy is
telling you. If you draw text and whatever to Canvas like you
do, then your drawings are temporarly (till the forms repaints).
Yes, you can invoke this by calling Form1->Repaint(), but it
would also happen if you tabbed through your open programs or
minimized and mazimized you app. Is that really what you want?
Normally you would not draw to a form's Canvas in an OnClick
event, for who knows how long your drawings will last? There
may be a system message popping up and your form will have to
repaint, i.e. you don't even have control over it. All painting
to the form should be done in its OnPaint event instead. When
the form repaints this event gets called and the text gets
repainted too. You problem would be however to remember all
drawings and redo them in OnPaint, i.e. you would use an array
where you place what to draw and the OnPaint would do the work.
(You know, an array of some struct like { "TextOut", "Hello
World", 200, 200 } and in OnPaint:
for(int i = 0; i < ...
if WhatToDo[i].Action == "TextOut")
Form1->Canvas->TextOutA(WhatToDo[i].X,WhatToDo[i].Y,WhatToDo[i].Text);
...
). To erase it you would then clear your array and call Repaint.
The other possiblity would be to use a bitmap. Either you would
place a TImage on your form and paint there and when you want to
erase it you use FillRect. Or you would use a hidden bitmap and
copy that in OnPaint to your form's Canvas.
Hope this clears things for you.
 

Re:Clear a form

"Michael Harrington" < XXXX@XXXXX.COM >wrote in message
Quote
void __fastcall TForm1::Button1Click(TObject *Sender)
{

Form1->Canvas->TextOutA(200,200,"Hello World");
}
As i already told you, such drawing is NOT persistent because you are not
using the form's OnPaint event. As soon as the form is re-painted, your
drawing is lost until you draw again. As such, you should be using the
OnPaint event, and then you can use a flag to control the drawing. For
example:
bool bDrawText = false;
void __fastcall TForm1::Button1Click(TObject *Sender)
{
if( !bDrawText )
{
bDrawText = true;
Invalidate();
}
}
void __fastcall TForm1::Button2Click(TObject *Sender)
{
if( bDrawText )
{
bDrawText = false;
Invalidate();
}
}
void __fastcall TForm1::FormPaint(TObject *Sender)
{
if( bDrawText )
Canvas->TextOut(200, 200, "Hello World");
}
Gambit