Solved

Print a Treeview

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

867 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

15 Experts available now in Live!

Get 1:1 Help Now