Mirror

How to print a TTreeView (Views: 100)


Problem/Question/Abstract:

How to print a TTreeView

Answer:

var
  bmp: TBitmap;
begin
  bmp := TBitmap.Create;
  try
    bmp.width := treeview.width;
    bmp.height := treeview.height;
    bmp.canvas.lock;
    try
      treeview.perform(WM_PRINT, bmp.canvas.handle, PRF_CHILDREN or
        PRF_CLIENT or PRF_NONCLIENT);
    finally
      bmp.canvas.unlock;
    end;
    { ... print the bitmap as device-independent bitmap }
  finally
    bmp.free
  end;
end;


Drawing directly to the printer canvas is probably possible but you have to mess with mapping modes, scale the printer canvas, move its origin and so on, the above may be easier to code, especially if you already have a PrintBitmap routine flying around somewhere.

<< Back to main page