BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

redraw a canvas to cleanup artifacts

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Graphics)
View previous topic :: View next topic  
Author Message
Guest






PostPosted: Wed Sep 20, 2006 8:31 pm    Post subject: redraw a canvas to cleanup artifacts Reply with quote



Hi;

I created a form
then I created a canvas


---------------
TCanvas* canvas = Form1->Canvas;

// created a TRect

TRect rect =Rect( 10, 10, 100, 100);

canvas->Brush->Color = clBlack;
canvas->Font->Color = clYellow;


//and finally a TextRect

canvas->TextRect(rect, 20, 20, "some text");


-------------------


I then created a button routine that moves the rectangle down on the
canvas. The problem is the area where the rectangle used to be is
still painted black so I end up with a visually larger rectangle al
though it is just a display artifact because re sizing the form clears
it up.


How do I get the canvas to repaint?

Thanks
Back to top
Guest






PostPosted: Wed Sep 20, 2006 8:37 pm    Post subject: Re: redraw a canvas to cleanup artifacts Reply with quote



On Wed, 20 Sep 2006 15:31:33 GMT, DeKayA (AT) bellsouth (DOT) net wrote:

I stuck an Invalidate() in each button click which does indeed redraw
the entire canvas. But it flashes pretty bad. anyway around this
Assuming Invalidate is the right choice?
Back to top
Clayton Arends
Guest





PostPosted: Wed Sep 20, 2006 8:41 pm    Post subject: Re: redraw a canvas to cleanup artifacts Reply with quote



<DeKayA (AT) bellsouth (DOT) net> wrote in message
news:45115d37.7620437 (AT) forums (DOT) borland.com...

Quote:
then I created a canvas

Perhaps a minor detail but you didn't *create* a canvas. You are
referencing the form's canvas.

Quote:
How do I get the canvas to repaint?

Since this canvas belongs to the form, and the form has a window handle, you
can use any API function that acts on a window handle. In this case
Invalidate() and InvalidateRect(). Check them out in the help but here is
an example:

TRect oldRect;
TRect newRect;
InvalidateRect(Form11->Handle, &oldRect, TRUE);
InvalidateRect(Form11->Handle, &newRect, FALSE);

HTH,
- Clayton
Back to top
Guest






PostPosted: Wed Sep 20, 2006 8:45 pm    Post subject: Re: redraw a canvas to cleanup artifacts Reply with quote

In the news group I saw references to doublebuffer but I didn't see
it as a property for my form I have BCB4

Does it exist. is it the right way to pursue?



On Wed, 20 Sep 2006 15:37:18 GMT, DeKayA (AT) bellsouth (DOT) net wrote:

Quote:
On Wed, 20 Sep 2006 15:31:33 GMT, DeKayA (AT) bellsouth (DOT) net wrote:

I stuck an Invalidate() in each button click which does indeed redraw
the entire canvas. But it flashes pretty bad. anyway around this
Assuming Invalidate is the right choice?


Back to top
Clayton Arends
Guest





PostPosted: Wed Sep 20, 2006 9:22 pm    Post subject: Re: redraw a canvas to cleanup artifacts Reply with quote

You have to set DoubleBuffered to true in code. In the form's constructor
put this:

DoubleBuffered = true;

- Clayton
Back to top
Guest






PostPosted: Wed Sep 20, 2006 9:32 pm    Post subject: Re: redraw a canvas to cleanup artifacts Reply with quote

Clayton
Thanks you have been a lot of help.
I tried your first suggestion

static TRect rect;
InvalidateRect(Form1->Handle, &rect, TRUE); // clears the rectangle
rect =Rect( g_RectX, g_RectY, Formwidth-10, g_RectY+Theight);
Application->ProcessMessages(); // Required or rect is not displayed


and it worked great.
not sure why you had two in your example one with it erase false.
didn't seem to make a difference. still required
Application->ProcessMessages();


Not even sure DoubleBuffered will be required now but I will go
experiment with it to see what I can learn

Thanks




On Wed, 20 Sep 2006 09:22:41 -0700, "Clayton Arends"
<nospam_claytonarends (AT) hotmail (DOT) com> wrote:

Quote:
You have to set DoubleBuffered to true in code. In the form's constructor
put this:

DoubleBuffered = true;

- Clayton
Back to top
Hans Galema
Guest





PostPosted: Thu Sep 21, 2006 12:37 am    Post subject: Re: redraw a canvas to cleanup artifacts Reply with quote

DeKayA (AT) bellsouth (DOT) net wrote:

Quote:
TCanvas* canvas = Form1->Canvas;

If that line and the rest of your code is used in an eventhandler
for a TButton on Form1 then there is a much cleaner approch.

Just use the forms property Canvas and delete that line.

Canvas->TextRect(rect, 20, 20, "some text");

Hans.
Back to top
Guest






PostPosted: Thu Sep 21, 2006 1:38 am    Post subject: Re: redraw a canvas to cleanup artifacts Reply with quote

Is that the difference between canvas and Canvas?


On Wed, 20 Sep 2006 21:37:48 +0200, Hans Galema <notused (AT) notused (DOT) nl>
wrote:

Quote:
DeKayA (AT) bellsouth (DOT) net wrote:

TCanvas* canvas = Form1->Canvas;

If that line and the rest of your code is used in an eventhandler
for a TButton on Form1 then there is a much cleaner approch.

Just use the forms property Canvas and delete that line.

Canvas->TextRect(rect, 20, 20, "some text");

Hans.
Back to top
Hans Galema
Guest





PostPosted: Thu Sep 21, 2006 3:59 am    Post subject: Re: redraw a canvas to cleanup artifacts Reply with quote

DeKayA (AT) bellsouth (DOT) net wrote:
Quote:
Is that the difference between canvas and Canvas?

Sorry. What do you mean with that question?

Hans.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Graphics) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.