在DELPHI中打印TDBGrid内容

时间:2010-01-31 10:01:05  来源:第二电脑网  作者:第二电脑网

  第二电脑网导读:bGrid:TDbGrid;Title:String);varPointX,PointY:integer;ScreenX:integer;i,lx,ly:integer;px1,py1,px2,py2:integer;RowPerPage,RowPrinted:integer;ScaleX:Real;THeight:integer;TitleWidth:integer;SumWidth:integer;PageCount:integer;SpaceX,SpaceY:integer;RowCount:integer;begin ...
  正文:打印TDBGrid中的内容,请看如下代码:


procedure PrintDbGrid(DataSet:TDataSet;DbGrid:TDbGrid;Title:String);
var
PointX,PointY:integer;
ScreenX:integer;
i,lx,ly:integer;
px1,py1,px2,py2:integer;
RowPerPage,RowPrinted:integer;
ScaleX:Real;
THeight:integer;
TitleWidth:integer;
SumWidth:integer;
PageCount:integer;
SpaceX,SpaceY:integer;
RowCount:integer;
begin
  PointX:=Round(GetDeviceCaphotoshop/ target=_blank class=infotextkey>ps(printer.Handle,LOGPIXELSX)/2.54);
PointY:=Round(GetDeviceCaps(printer.Handle,LOGPIXELSY)/2.54);
ScreenX:=Round(Screen.PixelsPerInch/2.54);
ScaleX:=PointX/ScreenX;
RowPrinted:=0;
  SumWidth:=0;
  printer.BeginDoc;
  With Printer.Canvas do
    begin
      DataSet.DisableControls;
      DataSet.First ;
      THeight:=Round(TextHeight('我')*1.5);//设定每行高度为字符高的1.5倍
   SpaceY:= Round(TextHeight('我')/4);
   SpaceX:=Round(TextWidth('我')/4);
   RowPerpage:=Round((printer.PageHeight-5*PointY)/THeight); //上下边缘各2厘米
   ly:=2*PointY;
      PageCount:=0;
      while not DataSet.Eof do
      begin
        if (RowPrinted=RowPerPage) or (RowPrinted=0) then
        begin
          if RowPrinted<>0 then
          Printer.NewPage;
          RowPrinted:=0;
          PageCount:=PageCount+1;
          Font.Name:='宋体';
          Font.size:=16;
          Font.Style:=Font.Style+[fsBold];
          lx:=Round((Printer.PageWidth-TextWidth(Title))/2);
       ly:=2*PointY;
          TextOut(lx,ly,Title);
          Font.Size:=11;
          Font.Style:=Font.Style-[fsBold];
          lx:=Printer.PageWidth-5*PointX;
          ly:=Round(2*PointY+0.2*PointY);
          if RowPerPage*PageCount>DataSet.RecordCount then
          RowCount:=DataSet.RecordCount
          else
          RowCount:=RowPerPage*PageCount;
          TextOut(lx,ly,'第'+IntToStr(RowPerPage*(PageCount-1)+1)+'-'+IntToStr(RowCount)+'条,共'+IntToStr(DataSet.RecordCount)+'条');
          lx:=2*PointX;
          ly:=ly+THeight*2;
          py1:=ly-SpaceY;
          if RowCount=DataSet.RecordCount then
          py2:=py1+THeight*(RowCount-RowPerPage*(PageCount-1)+1)
          else
          py2:=py1+THeight*(RowPerPage+1);
          SumWidth:=lx;
          for i:=0 to DBGrid.Columns.Count-1 do
          begin
            px1:=SumWidth-SpaceX;
            px2:=SumWidth;
            MoveTo(px1,py1);
            LineTo(px2,py2);
            TitleWidth:=TextWidth(DBGrid.Columns[i].Title.Caption);
            lx:=Round(SumWidth+(DBGrid.Columns[i].width*scaleX-titleWidth)/2);

"在DELPHI中打印TDBGrid内容"由第二电脑网原创提供,转载请注明:http://www.002pc.com/master/College/Language/Delphi/12685.html

 1/5    1 2 3 4 5 下一页 尾页


关键字:

关于《在DELPHI中打印TDBGrid内容》文章的评论

站内搜索: 高级搜索

热门搜索: Windows style 系统 tr IP QQ CPU 安装 function 注册 if td