Mega Code Archive

 
Categories / Delphi / Printing
 

How to print from a tlistview

unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ComCtrls, ExtCtrls; type TForm1 = class(TForm) Button1: TButton; ListView1: TListView; Image1: TImage; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); var bmp: TBitmap; begin bmp := Tbitmap.Create; try bmp.width := listview1.width; bmp.height := listview1.height; with bmp.canvas do begin Lock; try listview1.perform(WM_PRINT, handle, PRF_CHILDREN or PRF_CLIENT or PRF_NONCLIENT or PRF_ERASEBKGND); finally Unlock end; image1.picture.bitmap := bmp; end; finally bmp.free end; end; end.