Solved

Print a Treeview

Posted on 2002-04-15
4
498 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

821 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