Solved

Print a Treeview

Posted on 2002-04-15
4
464 Views
Last Modified: 2010-05-19
Does anyone have sample code on how to print a treeview to the printer?
0
Comment
Question by:CalvinDay
  • 2
  • 2
4 Comments
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 6943319
simple:

procedure TForm1.Button1Click(Sender: TObject);
var bmp: TBitmap;
begin
     bmp:=TBitmap.Create;
     try
        bmp.Width:=tv.Width;
        bmp.Height:=tv.Height;
        BitBlt(bmp.Canvas.Handle, 0, 0, tv.Width, tv.Height, tv.Canvas.Handle, 0, 0, SRCCOPY);
        im.Picture.Assign(bmp);
     finally
        FreeAndNil(bmp);
     end;
end;
0
 
LVL 12

Expert Comment

by:Lee_Nover
ID: 6943325
hum .. if you can print a bitmap then you can print this also :)

tv is TTreeView and im is TImage

hum .. since I don't have the printer I couldn't try it out ... but here's the complete code you need


uses printers;

procedure TForm1.Button1Click(Sender: TObject);
var bmp: TBitmap;
begin
     bmp:=TBitmap.Create;
     try
        bmp.Width:=tv.Width;
        bmp.Height:=tv.Height;
        BitBlt(bmp.Canvas.Handle, 0, 0, tv.Width, tv.Height, tv.Canvas.Handle, 0, 0, SRCCOPY);
        im.Picture.Assign(bmp);
        with Printer do
        begin
          BeginDoc;
          Canvas.Draw(0, 0, im.Picture.Graphic);
          EndDoc;
        end;
     finally
        FreeAndNil(bmp);
     end;
end;
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 6943485
That works great for those items in view, how about those items that are not in view?

Shane
0
 
LVL 11

Accepted Solution

by:
shaneholmes earned 100 total points
ID: 6943492
Quickly, this result writes to a file, then prints the file.  This is untested and unformatted - play with it to achieve the desired results....

procedure WriteTreeToFile( Var F: TextFile; Tree: TTreeview );
var
 Node: TreeNode;
begin
 Node:= Tree.Items.GetFirstnode;
 While Node <> Nil Do
 begin
  WriteLn(F, StringOfChar(' ', 2* Node.Level ),Node.Text );
  Node := Node.GetNext;
 end;
end;

var
 F: TextFile;

begin
 AssignPrn( F );
 Rewrite(F);
 try
  WriteTreeToFile( F, TreeView1 );
 finally
 CloseFile(F);
 end;
end;

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now