Board index » delphi » Canvas in TPaintBox VS. Canvas in TImage

Canvas in TPaintBox VS. Canvas in TImage

After i have done some experiments I find following fact but I dont know
whether its true or false.

All properties in canvas of TImage is persistent while TPaintBox not.
In paintbox  you have to maintain font and brush and ...
youself,everytime when you use it you must selectobject into it.

 

Re:Canvas in TPaintBox VS. Canvas in TImage


On Sun, 26 Jul 1998 13:32:19 +0800, guoguang <ga...@guoguang.com.cn>
wrote:

Quote
> All properties in canvas of TImage is persistent while TPaintBox not.

True, TImage "saves" whatever you draw onto a bitmap, while TPaintBox
is nothing more than a display canvas. Because of this, all painting
in a TPaintBox should occur in the OnPaint event.

Quote
> everytime when you use it you must selectobject into it.

I hope you aren't actually using the SelectObject Windows API -- that
is made unnecessary by the VCL's TCanvas class.

--
Rick Rogers (TeamB) | Fenestra Technologies
http://www.fenestra.com/

Re:Canvas in TPaintBox VS. Canvas in TImage


Is there anyway to make a PaintBox.Canvas persistent? Further, how do you
use PaintBox.Color or paint a background in PaintBox.Canvas? I can't get
either one to work.
Tony

 > All properties in canvas of TImage is persistent while TPaintBox not.

Quote

> True, TImage "saves" whatever you draw onto a bitmap, while TPaintBox
> is nothing more than a display canvas. Because of this, all painting
> in a TPaintBox should occur in the OnPaint event.

Re:Canvas in TPaintBox VS. Canvas in TImage


Quote
guoguang wrote:

> After i have done some experiments I find following fact but I dont know
> whether its true or false.

> All properties in canvas of TImage is persistent while TPaintBox not.
> In paintbox  you have to maintain font and brush and ...
> youself,everytime when you use it you must selectobject into it.

       Positively not. Put a paintbox on a form. Attach the following
event handler to the paintbox's OnPaint event:

procedure TForm1.PaintBox1Paint(Sender: TObject);
begin
with (Sender as TPaintbox).Canvas do
begin
  Rectangle(0,0,100,30);
  TextOut(10, 10, 'rectangle');
end;
end;

--
David Ullrich

sig.txt not found

Re:Canvas in TPaintBox VS. Canvas in TImage


On 27 Jul 1998 19:45:13 GMT, "Anthony Costanza"

Quote
<cost...@ix.netcom.com> wrote:
> Is there anyway to make a PaintBox.Canvas persistent?

Not without using a TBitmap, in which case you are better off just
using a TImage. That's the way Windows painting works -- it isn't
persistent, because persistence (i.e., bitmaps) is _very expensive_
with respect to memory.

Quote
> Further, how do you use PaintBox.Color or paint a background
> in PaintBox.Canvas?

A TPaintbox is for painting. It doesn't do any painting for you at all
-- you must do any painting you want in the OnPaint event. This
includes painting the background a particular color. The TPaintBox
Color property assigns a value to the TPaintBox.Canvas.Brush.Color.
You would use this color, for example, by using the Canvas.FillRect
method.

--
Rick Rogers (TeamB) | Fenestra Technologies
http://www.fenestra.com/

Re:Canvas in TPaintBox VS. Canvas in TImage


What I concerned was the properties of canvas in paintbox like
font,brush NOT the contents you draw in the paintbox.The fact is,even
you have set font's size to 12 at first time you have to REset it next
time when you use the canvas again otherwise the size of text you draw
is in default size(maybe 8,not 12).

So I dont know whether there are something wrong with me to result it.

Re:Canvas in TPaintBox VS. Canvas in TImage


On Tue, 28 Jul 1998 15:57:16 +0800, guoguang <ga...@guoguang.com.cn>
wrote:

Quote
> The fact is,even you have set font's size to 12 at first time you have to
> REset it next time when you

True, this is due to the fact that Delphi intelligently conserves GDI
resources for TGraphicControls -- their canvas is actually the same as
the parent's, so any changes to the parent's canvas (such as setting a
font) will affect the TPaintBox's canvas. This is normal, working as
designed, and designed well (to save on resources).

--
Rick Rogers (TeamB) | Fenestra Technologies
http://www.fenestra.com/

Re:Canvas in TPaintBox VS. Canvas in TImage


Quote
guoguang wrote:

> What I concerned was the properties of canvas in paintbox like
> font,brush NOT the contents you draw in the paintbox.The fact is,even
> you have set font's size to 12 at first time you have to REset it next
> time when you use the canvas again otherwise the size of text you draw
> is in default size(maybe 8,not 12).

> So I dont know whether there are something wrong with me to result it.

        Try setting thePaintBox.ParentFont:= False, then set
thePaintBox.Font to the font you want. See if it modifies itself
then.

--
David Ullrich

sig.txt not found

Other Threads