Board index » delphi » Problem on TCanvas

Problem on TCanvas

Hello all

I have a little problem with TCanvas. Can you help me?

In a soft, I create a bitmap:
B := TBitmap.Create;
B.width := width;
B.height := height;

I code an Onclick button like that:
B.Canvas.Moveto(0,0);
B.Canvas.lineto(width, height);

With second button:
Canvas.Stretchdraw(Rect(0,0,width,height), B);

And I get the line on my form.

But I cover my form with another app, my line disappear. No persistence ...

If I add a TImage on my form and I change my code to draw my bitmap on
TImage,
With second button:
Image1.Canvas.Stretchdraw(Rect(0,0,width,height), B);
I can change app, load excel, word, etc . If I return on ma delphi app, the
line is always displayed.
the TImage.Canvas preserve my previous draw.

However, It's a canvas in the two cases.

What's wrong please?

--
Alphomega
mailto:alfom...@club-internet.fr

 

Re:Problem on TCanvas


You need to do your drawing in the OnPaint event. When a form is
uncovered WIndows sends a message telling the form to repaint itself. If
your drawing isn't in OnPaint then only the form is redrawn. TImage
takes care of this for you.

Mitch Wolberg,
RockWare, Inc.

Quote
Alphomega wrote:

> Hello all

> I have a little problem with TCanvas. Can you help me?

> In a soft, I create a bitmap:
> B := TBitmap.Create;
> B.width := width;
> B.height := height;

> I code an Onclick button like that:
> B.Canvas.Moveto(0,0);
> B.Canvas.lineto(width, height);

> With second button:
> Canvas.Stretchdraw(Rect(0,0,width,height), B);

> And I get the line on my form.

> But I cover my form with another app, my line disappear. No persistence ...

> If I add a TImage on my form and I change my code to draw my bitmap on
> TImage,
> With second button:
> Image1.Canvas.Stretchdraw(Rect(0,0,width,height), B);
> I can change app, load excel, word, etc . If I return on ma delphi app, the
> line is always displayed.
> the TImage.Canvas preserve my previous draw.

> However, It's a canvas in the two cases.

> What's wrong please?

> --
> Alphomega
> mailto:alfom...@club-internet.fr

Re:Problem on TCanvas


Nothing is wrong.
You should just know that whatever you draw on the forms canvas is NOT
persistent.
This is how the form.canvas works.
This means that you will have to draw it again everytime it is needed on the
forms canvas.
This should be done in the forms OnPaint event.

Alphomega <alfom...@club-internet.fr> skrev i en
nyhedsmeddelelse:7r5o0t$35...@front6.grolier.fr...

Quote
> But I cover my form with another app, my line disappear. No persistence
...
> the TImage.Canvas preserve my previous draw.
> However, It's a canvas in the two cases.
> What's wrong please?

Other Threads