Solved

Print a Treeview

Posted on 2002-04-15
4
532 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses
Course of the Month10 days, 10 hours left to enroll

628 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