Board index » delphi » How to Print Paintbox.Canvas

How to Print Paintbox.Canvas

Hello everyone,

I'm working in D5 enterprise.  I have an app that's basically a drawing
tool.  It allows the user to draw lines, shapes, surfaced shapes, arcs, etc.
It's quite similar to a cad program.  I'm using Paintbox.Canvas.

The problem is I would like to give the user the capability to print his
drawing.  How would I do that?

Any help is greatly appreciated.

Pete

 

Re:How to Print Paintbox.Canvas


Take your existing routine to paint to the PaintBox canvas, and route it to
the Printer.Canvas.

Check out the Printer object, and especially the following:

        Printer.BeginDoc;
        Printer.EndDoc;

- Carl.

Quote
"Peter Lialios" <plial...@e-estimating.com> wrote in message

news:3ba60d20_2@dnews...
Quote
> Hello everyone,

> I'm working in D5 enterprise.  I have an app that's basically a drawing
> tool.  It allows the user to draw lines, shapes, surfaced shapes, arcs,
etc.
> It's quite similar to a cad program.  I'm using Paintbox.Canvas.

> The problem is I would like to give the user the capability to print his
> drawing.  How would I do that?

> Any help is greatly appreciated.

> Pete

Re:How to Print Paintbox.Canvas


Quote
Peter Lialios wrote:

> I'm working in D5 enterprise.  I have an app that's basically a drawing
> tool.  It allows the user to draw lines, shapes, surfaced shapes, arcs, etc.
> It's quite similar to a cad program.  I'm using Paintbox.Canvas.
> The problem is I would like to give the user the capability to print his
> drawing.  How would I do that?

The best free way is to use the StretchDIBits API call.  
See Item #1, "How can I print a bitmap?" at
http://www.efg2.com/Lab/Library/Delphi/Printing

Sometimes StretchDIBits will fail and you need the 'industrial strength
solution'
from Joe Hecht (at cost):
Joe Hecht's TExcellentImagePrinter
http://www.code4sale.com/joehecht/prndib.htm

--
Charles Hacker
Lecturer in Electronics and Computing
School of Engineering
Griffith University - Gold Coast
Australia

Re:How to Print Paintbox.Canvas


Carl,

I've been looking at the Printer.Canvas but haven't been able to use it
properly.

Lets say I have a menu option to print.  Would the code look like this:

procedure printpaintbox;
var
  prn: TPrinter;
begin
  prn := TPrinter.Create;
  with prn do begin
    begindoc;
    canvas := PaintBox.Canvas
    enddoc;
  end;
end;

The problem with this code is that I get an error stating that prn.canvas is
read-only and that I can't assign anything to it.

Do you have any ideas.

Thanks,

Pete

Quote
"Carl Olsen" <carlol...@omax.com> wrote in message

news:3ba662ee$1_1@dnews...
Quote

> Take your existing routine to paint to the PaintBox canvas, and route it
to
> the Printer.Canvas.

> Check out the Printer object, and especially the following:

>         Printer.BeginDoc;
>         Printer.EndDoc;

> - Carl.

> "Peter Lialios" <plial...@e-estimating.com> wrote in message
> news:3ba60d20_2@dnews...
> > Hello everyone,

> > I'm working in D5 enterprise.  I have an app that's basically a drawing
> > tool.  It allows the user to draw lines, shapes, surfaced shapes, arcs,
> etc.
> > It's quite similar to a cad program.  I'm using Paintbox.Canvas.

> > The problem is I would like to give the user the capability to print his
> > drawing.  How would I do that?

> > Any help is greatly appreciated.

> > Pete

Re:How to Print Paintbox.Canvas


Hi Peter,

Quote
> The problem with this code is that I get an error stating that prn.canvas
is
> read-only and that I can't assign anything to it.

In fact what you do is replace in all your calls Paintbox.Canvas by
Printer.Canvas.

An easy way to do this is to declare a variable CurrentCanvas and use it in
all graphics functions. When you draw, CurrentCanvas is set to
PaintBox.Canvas, when you print it is set to Printer.Canvas.

Thrse

Other Threads