Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Print a Treeview

Posted on 2002-04-15
4
Medium Priority
?
577 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 400 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

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…
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…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

886 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