中国程序员联盟 正在重新改版中ing 不便之处还请见谅 改版后将内容涉及java delphi .net php
 
  首页 | 数据库开发 | 网络通讯 | 多线程 | 多媒体开发 | 图像处理 | 程序人生 | 系统函数 | 控件开发 | Web服务
 
  当前位置:笨鱼delphi技术网>数据库开发>打印报表>文章内容

delphi 获取打印机边距

来源:站内 关于:bill 发布时间:2007-06-23   [收藏] [推荐]

uses Printers;

procedure TForm1.Button1Click(Sender: TObject);
var
  EscapeCode : integer;
  Margin : TPoint;
begin
  if PrintDialog1.Execute then begin
   {$IFDEF WIN32}
    Margin.x :=GetDeviceCaps(Printer.Handle, PHYSICALOFFSETX);
    Margin.y :=GetDeviceCaps(Printer.Handle, PHYSICALOFFSETY);
   {$ELSE}
    EscapeCode := GETPRINTINGOFFSET;
    if Escape(Printer.Handle,
              QUERYESCSUPPORT,
              sizeof(EscapeCode),
              @EscapeCode,
              nil) <> 0 then
      if Escape(Printer.Handle,
                GETPRINTINGOFFSET,
                0,
                nil,
                @Margin) < 1  then begin
       EscapeCode := GETPHYSPAGESIZE;
       if Escape(Printer.Handle,
                 QUERYESCSUPPORT,
                 sizeof(EscapeCode),
                 @EscapeCode,
                 nil) <> 0 then
        if Escape(Printer.Handle,
                  GETPHYSPAGESIZE,
                  0,
                  nil,
                  @Margin) > 0  then begin
          Margin.x := (Margin.x -
                       GetDeviceCaps(Printer.Handle, HorzRes)) div 2;
          Margin.y := (Margin.y -
                       GetDeviceCaps(Printer.Handle, VertRes)) div 2;
        end else begin
          Margin.x := 0;
          Margin.y := 0;
        end;
      end;
   {$ENDIF}
    Memo1.Lines.Add(IntToStr(Margin.x));
    Memo1.Lines.Add(IntToStr(Margin.y));
  end;
end;
///////////////////////////////////////////////////////////////
获得边缘坐标
var
  pntMargins : TPoint;
begin
  Escape(Printer.Handle, GETPRINTINGOFFSET,0,nil,@prntMargins);
end;

Getting the Right and Bottom Margins aren't quite so straightforward. There isn't an equivalent Escape call. You obtain these values by getting the physical width (physWidth) and height (physHeight) of the page, the printable width (PrintWidth) and height (PrintHeight) of the page, and then carrying out the following sums:

RightMargin    := physWidth  - PrintWidth  - LeftMargin
BottomMargin := physHeight - PrintHeight - TopMargin
The physical page size is found using Escape, this time with the GETPHYSPAGESIZE parameter. The point pntPageSize contains the page width in pntPageSize.x and page height in pntPageSize.y

var
  pntPageSize : TPoint;
begin
   Escape(Printer.Handle,     GETPHYSPAGESIZE,o,nil,@pntPageSize);
end;


[浏览: 次]   
上一篇:delphi 判断打印机是否能打印图像   下一篇:delphi 在打印中间改变打印设置
[收藏] [推荐] [返回顶部] [打印本页] [关闭窗口]  
    评论加载中…
google adsense热点文章
·delphi 获取打印机状态
·delphi 打印时改变纸张大小
·delphi 判断打印机能否打印的PostScrip
·delphi 检测存在打印机
·delphi Tmemo,TstringList,Tstrings打
·delphi 如何保存打印机信息到注册表
·delphi 判断系统是否有打印机连接
·delphi 在打印中间改变打印设置
·delphi 获取打印驱动,打印端口名
·delphi 使用打印机内置字体打印
·delphi 改变打印机的打印端口
·delphi 如何发二进制字符到打印机
     delphi技术网 | firefox 下载 | Avant Browser下载 | dedecms 技术网 | drupal 爱好者 | php 技术网
  Copyright@www.delphichm.com,2006-2009.All Rights Reserved.
 
程序员联盟 | delphi Java .net|QQ:707102932