如何在Delphi中设置打印机属性
2016-11-16 · 知道合伙人软件行家
关注
展开全部
在 delphi 中设置打印机属性方法如下:
一、使用打印机设置对话框:
PrinterSetupDialog1.Execute;
二、使用代码进行设置:
以下代码来源于网络:
procedure setprint(pagesize:tpagesize;width,height:variant;Orientation:tprinterOrientation);
var
Device: array[0..255] of char;
Driver: array[0..255] of char;
Port: array[0..255] of char;
hDMode: THandle;
PDMode: PDEVMODE;
begin
//设置打印机
try
Printer.PrinterIndex := Printer.PrinterIndex;
Printer.GetPrinter(Device, Driver, Port, hDMode);
if hDMode <> 0 then
begin
pDMode := GlobalLock(hDMode);
if pDMode <> nil then
begin
if pagesize=Custom then
begin
//设定自定义纸张
pDMode^.dmFields := pDMode^.dmFields or
dm_PaperSize or
DM_PAPERWIDTH or
DM_PAPERLENGTH;
pDMode^.dmPaperSize := 0;
pDMode^.DMPAPERWIDTH:= width*10 ;
pDMode^.DMPAPERLENGTH:=height*10;
end
else
begin
//设定纸张类型
pDMode^.dmFields := pDMode^.dmFields or
DM_PAPERSIZE ;
if pagesize=A3 then pDMode^.dmPaperSize := DMPAPER_A3;
if pagesize=A4 then pDMode^.dmPaperSize := DMPAPER_A4;
if pagesize=A5 then pDMode^.dmPaperSize := DMPAPER_A5;
if pagesize=B4 then pDMode^.dmPaperSize := DMPAPER_B4;
if pagesize=B5 then pDMode^.dmPaperSize := DMPAPER_B5;
if pagesize=CSheet then pDMode^.dmPaperSize := DMPAPER_CSheet;
if pagesize=Executive then pDMode^.dmPaperSize := DMPAPER_Executive;
if pagesize=Letter then pDMode^.dmPaperSize:= DMPAPER_Letter;
end;
printer.Orientation:=Orientation;
GlobalUnlock(hDMode);
end;
end ;
Printer.PrinterIndex := Printer.PrinterIndex;
except
showmessage('没有默认选择打印机,或默认打印机不可使!');
exit;
end;
end;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询