var
DMode: PDevMode;
h: THandle;
Device, Drive, Port: PChar;
OldLeft: Integer;
begin
with Printer do
begin
Device := StrAlloc(255);
Drive := StrAlloc(255);
Port := StrAlloc(255);
GetPrinter(Device, Drive, Port, h);
DMode := LocalLock(h);
DMode.dmPaperSize := 256;
DMode.dmPaperLength := 2100;
DMode.dmPaperWidth := 2000;
LocalUnLock(h);
SetPrinter(Device, Drive, Port, h);
StrDispose(Device);
StrDispose(Drive);
StrDispose(Port); BeginDoc;
OldLeft := MainPanel.Left;
MainPanel.Left := 1500;
try
MainPanel.ScaleBy(200, 100);
MainPanel.PaintTo(Handle, 30, 10);
MainPanel.ScaleBy(100, 200);
finally
MainPanel.Left := OldLeft;
end;
EndDoc;
end;
.................
end;
{ 以上代码实现Panel中打印,用针式打印机可以打印正常,但用喷墨,激光打印机
打印出来的内容就非常小,不是针式打印机打印出来的实际尺寸,请赐教,谢谢! }
DMode: PDevMode;
h: THandle;
Device, Drive, Port: PChar;
OldLeft: Integer;
begin
with Printer do
begin
Device := StrAlloc(255);
Drive := StrAlloc(255);
Port := StrAlloc(255);
GetPrinter(Device, Drive, Port, h);
DMode := LocalLock(h);
DMode.dmPaperSize := 256;
DMode.dmPaperLength := 2100;
DMode.dmPaperWidth := 2000;
LocalUnLock(h);
SetPrinter(Device, Drive, Port, h);
StrDispose(Device);
StrDispose(Drive);
StrDispose(Port); BeginDoc;
OldLeft := MainPanel.Left;
MainPanel.Left := 1500;
try
MainPanel.ScaleBy(200, 100);
MainPanel.PaintTo(Handle, 30, 10);
MainPanel.ScaleBy(100, 200);
finally
MainPanel.Left := OldLeft;
end;
EndDoc;
end;
.................
end;
{ 以上代码实现Panel中打印,用针式打印机可以打印正常,但用喷墨,激光打印机
打印出来的内容就非常小,不是针式打印机打印出来的实际尺寸,请赐教,谢谢! }
DMode: PDevMode;
h: THandle;
Device, Drive, Port: PChar;
OldLeft, pcdpi,prdpi,natio: Integer;
begin
with Printer do
begin
//------------------------------这段代码是不是在喷墨打印机上打有问题?
Device := StrAlloc(255);
Drive := StrAlloc(255);
Port := StrAlloc(255);
GetPrinter(Device, Drive, Port, h);
DMode := LocalLock(h);
DMode.dmPaperSize := 256;
DMode.dmPaperLength := 2100;
DMode.dmPaperWidth := 2000;
LocalUnLock(h);
SetPrinter(Device, Drive, Port, h);
StrDispose(Device);
StrDispose(Drive);
StrDispose(Port);
// -----------------------------------------------
BeginDoc;
//这里以x轴大小为例,还可以取得y的分辨率
{ --------------------------}
pcdpi:=getdevicecaps(getdc(0),LOGPIXELSX);
prdpi:=getdevicecaps(printer.handle,LOGPIXELSX);
natio:=round(prdpi/pcdpi); OldLeft := MainPanel.Left *natio;
MainPanel.Left := 1500*natio; try
MainPanel.ScaleBy(200*natio, 100*natio);
MainPanel.PaintTo(Handle, 30*natio, 10*natio);
MainPanel.ScaleBy(100*natio, 200*natio);
finally
MainPanel.Left := OldLeft*natio;
end; EndDoc;
end;
end;
// 请高手提出一些建议呀,谢谢!
MainPanel.ScaleBy(200*natio, 100*natio);
MainPanel.PaintTo(Handle, 30*natio, 10*natio);
MainPanel.ScaleBy(100*natio, 200*natio);
改为
MainPanel.ScaleBy(100*natio, 100);
MainPanel.PaintTo(Handle, 30*natio, 10*natio);
MainPanel.ScaleBy(100 , 100*natio);