如何在Delphi中设置打印机属性
答案:1 悬赏:0 手机版
解决时间 2021-02-15 06:54
- 提问者网友:未信
- 2021-02-15 00:53
如何在Delphi中设置打印机属性
最佳答案
- 五星知识达人网友:玩世
- 2021-02-15 02:04
在 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;
一、使用打印机设置对话框:
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;
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯