如题。

解决方案 »

  1.   

    procedure draw();
    var i,j,cwidth:integer;
    begin
        for i:=0 to pagecount-1 do
        begin
           printfile[i].Free;
        end;
       PointX:=GetDeviceCaps(printer.Handle,LOGPIXELSX)/25.4;//每毫米打印机的像素数
       PointY:=GetDeviceCaps(printer.Handle,LOGPIXELSy)/25.4;
       xx:=PointX/(screen.PixelsPerInch/25.4);
       yy:=PointY/(screen.PixelsPerInch/25.4);
       PointX:=PointX/xx;
       Pointy :=PointY/yy;
       pagecount:=1;
       cwidth:=0;
       Recordcount:=0;
       setlength(printfile,pagecount) ;
       printfile[pagecount-1]:= TMetafile.Create;
       printcanvas:=tmetafilecanvas.Create(printfile[pagecount-1],0);
       previewfrm.ScrollBox1.HorzScrollBar.Position:=0;
       previewfrm.ScrollBox1.VertScrollBar.Position:=0;
       with previewfrm.Image1 do
         begin
           Width:=printer.PageWidth/xx;
           Height:=printer.PageHeight/yy;
           Left:=1;
           Top:=1;
         end;
       with previewfrm.Panel1 do
         begin
           WIDTH:=previewfrm.Image1.Width+2;
           height:=previewfrm.Image1.Height+2;
           left:=5;
           top:=5;
         end;
       coltitlewidth:=0;
       pleft:=strtofloat(zhizhang[0])*PointX;
       pright:=strtofloat(zhizhang[1])*PointX;
       ptop:=strtofloat(zhizhang[2])*PointY;
       pbottom:=strtofloat(zhizhang[3])*PointY;
       pwidth:=previewfrm.Image1.width-pleft-pright;
       pheight:=previewfrm.Image1.Height-ptop-pbottom;
       //计算网格每列长度占总长的比例并得到在纸张上相映的位置   SetLength(colsX,len);
       SetLength(colswidth,len);
       for i:=0 to len-1 do cwidth:=cwidth+strtoint(s[i]);
       for i:=0 to len-1 do colswidth[i]:=(strtoint(s[i])/cwidth)*pwidth;
       colsx[0]:=pleft;
       for i:=1 to len-1 do colsx[i]:=colsx[i-1]+colswidth[i-1];
       x:=pleft;
       y:=ptop;
       detailfootheight:=0;
       with printcanvas do
         begin
           if mingxi[0]='Vertical' then
             begin
               Font.Name:= liebaioti[2];
               Font.Color:=strtoint(liebaioti[3]);
               Font.Size:=strtoint(liebaioti[4]);
               Font.Style:= strtoFontStyle(liebaioti[5]);
               for i:=0 to length(liebaiotistr)-1 do
                if coltitlewidth<TextWidth(liebaiotistr[i]) then coltitlewidth:=TextWidth(liebaiotistr[i]);
             end;
           if strtobool(mingxiwei[0]) then
             begin
               Font.Name:= mingxiwei[3];
               Font.Color:=strtoint(mingxiwei[4]);
               Font.Size:=strtoint(mingxiwei[5]);
               Font.Style:= strtoFontStyle(mingxiwei[6]);
               detailfootheight:=TextHeight('无')+10/yy;
             end;
             if strtobool(yemei[0]) then
               begin
                 previewpageheader;
                 y:=y+20/yy;
               end;
           if strtobool(biaoti[0]) then previewtitle;
           y:=y+strtoint(mingxi[3])*PointY;
           if strtobool(mingxitou[0]) then previewDetailhead;
           Pen.Color:=strtoint(biankuang[0]);
           Pen.Style:=strtopenStyle(biankuang[1]);
           Pen.Width:=strtoint(biankuang[2]);
           Polyline([point(x,y),point(pwidth+pleft,y)]);
           if strtobool(liebaioti[0]) and (strtoArrange(mingxi[0])<>Vertical) and not strtobool(liebaioti[8]) then previewcolstitle;
           Pen.Color:=strtoint(biankuang[0]);
           Pen.Style:=strtopenStyle(biankuang[1]);
           Pen.Width:=strtoint(biankuang[2]);
           Polyline([point(x,y),point(pwidth+pleft,y)]);
           Pen.Color:=strtoint(hengxian[0]);
           Pen.Style:=strtopenStyle(hengxian[1]);
           Pen.Width:=strtoint(hengxian[2]);
           Polyline([point(x,y),point(pwidth+pleft,y)]);
           hang:=0;
           while memo[hang]<>'???????????????????????????????????????????????' do  hang:=hang+1;
           hang:=hang+1;
           for i:=hang to memo.Count-2 do
            begin
              len:=0;   //读入各个字段内容
              SetLength(mingxistr,len);
              for j:=0 to length(widestring(memo[hang])) do
                if widestring(memo[hang])[j]='┆' then
                  begin
                    len:=len+1;
                    SetLength(mingxistr,len);
                  end else if len>0 then mingxistr[len-1]:=mingxistr[len-1]+widestring(memo[hang])[j];
                 if y+detailrowheight+detailfootheight>pheight+ptop then
                   begin
                     Pen.Color:=strtoint(biankuang[0]);
                     Pen.Style:=strtopenStyle(biankuang[1]);
                     Pen.Width:=strtoint(biankuang[2]);
                     Polyline([point(x,y),point(pwidth+pleft,y)]);
                     Pen.Color:=strtoint(hengxian[0]);
                     Pen.Style:=strtopenStyle(hengxian[1]);
                     Pen.Width:=strtoint(hengxian[2]);
                     Polyline([point(x,y),point(pwidth+pleft,y)]);
                     if strtobool(yejiao[0]) then previewpagefooter;
                     //*******换页*********
                     Free;
                     pagecount:=pagecount+1;
                     setlength(printfile,pagecount) ;
                     printfile[pagecount-1]:= TMetafile.Create;
                     printcanvas:=tmetafilecanvas.Create(printfile[pagecount-1],0);
                     with previewfrm do
                       begin
                         StatusBar1.Panels[3].Text:=inttostr(pagecount);
                         if pagecount>1 then
                           begin
                             Image1.Picture:=nil;
                             Panel1.Visible:=true;
                             Image1.Canvas.Draw(0,0,printfile[0]);
                             StatusBar1.Panels[1].Text:='1';
                           end;
                         Update;
                       end;
                     //*******换页*********
                     x:=pleft;
                     y:=ptop;
                     if strtobool(yemei[0]) then
                        begin
                           previewpageheader;
                           y:=y+20/yy;
                        end;
                     if strtobool(biaoti[8]) and strtobool(biaoti[0]) then previewtitle ;
                     if strtobool(liebaioti[0]) and (strtoArrange(mingxi[0])<>Vertical) and strtobool(liebaioti[7]) and not strtobool(liebaioti[8]) then previewcolstitle  else //每页打印列标题
                       begin
                         Pen.Color:=strtoint(biankuang[0]);
                         Pen.Style:=strtopenStyle(biankuang[1]);
                         Pen.Width:=strtoint(biankuang[2]);
                         Polyline([point(x,y),point(pwidth+pleft,y)]);
                       end;
                   end;
                 if strtobool(liebaioti[0]) and (strtoArrange(mingxi[0])<>Vertical)  and strtobool(liebaioti[8]) then previewcolstitle; //每个明晰打印列标题
                 previewDetail;
                 Recordcount:=Recordcount+1;
                 Pen.Color:=strtoint(hengxian[0]);
                 Pen.Style:=strtopenStyle(hengxian[1]);
                 Pen.Width:=strtoint(hengxian[2]);
                 Polyline([point(x,y),point(pwidth+pleft,y)]);
                 hang:=hang+1;
            end;
            Pen.Color:=strtoint(biankuang[0]);
            Pen.Style:=strtopenStyle(biankuang[1]);
            Pen.Width:=strtoint(biankuang[2]);
            Polyline([point(x,y),point(pwidth+pleft,y)]);
            if strtobool(mingxiwei[0]) then  previewDetailfoot;
            if strtobool(yejiao[0]) then  previewpagefooter;
            Free;
         end;
       if pagecount<2 then  with  previewfrm do
         begin
           Image1.Picture:=nil;
           Panel1.Visible:=true;
           Image1.Canvas.Draw(0,0,printfile[0]);
           StatusBar1.Panels[1].Text:='1';
           StatusBar1.Panels[3].Text:='1';
           Update;
         end;
    end;这是我做的预览得一段代码?希望对你有点帮助!
      

  2.   

    请问在D6中没有这样的控件吗?我的QQ:80741274      [email protected]
      

  3.   

    QReport里面的东西
    都可以打印预览
      

  4.   

    预览的方式太多了,qreport是delphi自带的控件,不过Delphi7里面要手工添加到控件面板里