请问各位高手:
    怎么实现ListView的打印预览和打印???一定给分!如果有例子可以发到:[email protected]
                谢谢!!!

解决方案 »

  1.   

    Delphi文本和图形的打印方法
    一、基本知识1、在代码单元的Uses部分增加Printers,打印实际上是把要打印的内容画到tprinter的canvas画布上。2、选择输出的打印机:printdialog1.execute3、选择打印控制选项 printersetupdialog1.execute;
    二、打印文本//打印Memo1中的内容procedure TForm1.BitBtn1Click(Sender: TObject);varlines:integer;prntext:text; 定义打印文本变量beginif printdialog1.execute thenassignprn(prntext); //将prntext文件分配给打印机rewrite(prntext); //打开prntext文件printer.canvas.font:=memo1.font; //设置打印对象的canvas的字体for lines:=0 to memo1.lines.count-1 dowriteln(prntextmemo1.lines[lines]); //把Memo1的内容写到打印机对象system.close(prntext); //关闭打印文件end;
    三、打印图形1、利用打印机的分辨率,图形将打印在页面的左上角,图形较小。procedure TForm1.BitBtn1Click(Sender: TObject);beginif printdialog1.execute thenbeginprinter.begindoc;printer.canvas.draw(00image1.picture.graphic);printer.enddoc;end;end;2、利用打印机画布canvas的stretchdraw方法可以对图形进行更为灵活的处理。其中要用到一个代表图形输出区域的Rect参数Trect的类型定义如下:TRect = recordcase Integer of0: (LeftTopRightBottom: Integer);1: (TopLeftBottomRight: TPoint);end;  
    例:通过调整Rect的范围、图形大小及其在打印页面上的位置,实现图形打印:procedure TForm1.Button1Click(Sender: TObject);var strect:Trect; //定义打印输出矩形框的大小temhitemwd:integer;beginif printdialog1.execute thenbegintemhi:=image1.picture.height;temwd:=image1.picture.width;while (temhi<printer.pageheight div 2) and //将图形放大到打印页面的1/2 (temwd<printer.pagewidth div 2) do begintemhi:=temhi+temhi;temwd:=temwd+temwd;end;with strect do //定义图形在页面上的中心位置输出beginleft:=(printer.pagewidth -temwd) div 2;top:=(printer.pageheight-temhi) div 2;right:=left+temwd;bottom:=top+temhi;end;with Printer do beginbegindoc; //将放大的图形向打印机输出canvas.stretchdraw(strectimage1.picture.graphic);enddoc;end;end;end; 记得给分:)
      

  2.   

    看完后应该很简单了吧,记住要勤学,不要什么都靠别人。
    procedure TForm1.Button1Click(Sender: TObject);
    var
      f: textfile;
      i,j : integer;
      str : string;
    begin
      assignfile(f,'c:\test.txt');
      rewrite(f);
      str := '';
      for i := 0 to listview1.Columns.Count - 1 do
        str := str + listview1.Columns[i].Caption + '    ';
      writeln(f,str);
      str := '========================';
      writeln(f,str);
      for i := 0 to listview1.Items.Count - 1 do
      begin
        str := listview1.Items[i].Caption + '    ';
        for j := 0 to listview1.Items[i].SubItems.Count - 1 do
          str := str + listview1.Items[i].SubItems[j] + '    ';
        writeln(f,str);
      end;
      closefile(f);
    end; 
      

  3.   

    用控件也很好呀!
    http://www.tmssoftware.com 上应该有!