我有一个表格,我需要打印但只有它的某个部分,然后放大它(增加比例)。到目前为止,我有以下代码:德尔福打印一个表格的自定义区域
procedure TForm1.PrintButtonClick(Sender: TObject);
var
printDialog : TPrintDialog;
begin
printDialog := TPrintDialog.Create(Form1);
if printDialog.Execute then
begin
Printer.Orientation := poLandscape; //Better fit than portrait
Form1.PrintScale:=poPrintToFit;
Form1.Print;
end;
end;
但是,这会打印整个表单。我搜索了一下,发现了几个不同的东西可能会有帮助,但我不知道如何使用它们:
GetFormImage - 有没有一种方法可以选择一个特定的区域,或者它只是采取整个表单?使用具有给定坐标的矩形,例如矩形1:=矩形(左,上,右,下);但是如何将矩形打印成更大尺寸并打印?同样,看起来Delphi只提供Left和Top属性,Right是你想要去的最远左值的另一个名字?
更新: 我试图创建一个自定义位图,然后拉伸它,但我没有正确使用strechdraw。它在印刷时并不实际拉伸:
procedure TForm1.PrintButtonClick(Sender: TObject);
var
printDialog: TPrintDialog;
Rectangle, stretched: TRect;
Bitmap: TBitmap;
begin
Bitmap := TBitmap.Create;
try
Rectangle := Rect(0, 90, 1450, 780);
stretched := Rect(0, 0, 5000, 3000); //what numbers do i put in here for streching it?
Bitmap.SetSize(Form1.Width, Form1.Height);
Bitmap.Canvas.CopyRect(Rectangle, Form1.Canvas, Rectangle);
Bitmap.Canvas.StretchDraw(stretched, Bitmap); //not sure how to use this
finally
printDialog := TPrintDialog.Create(Form1);
if printDialog.Execute then
begin
with printer do
begin
BeginDoc;
Canvas.Draw(0, 90, Bitmap);
EndDoc;
end;
end;
Bitmap.Free;
end;
end;
是否尝试,最后是必要的? 当我打印而不stretchdraw这是非常小的,但是当我印有stretchdraw,很多图像的缺失,所以我必须使用它错了
什么“新布局”?自从我使用这个网站以来,至少已有4-5年的时间,它的工作方式也是一样的。选择您的代码,然后单击“格式代码”按钮。 –
@JerryDodge我知道Id改变了一些东西。我偶然切换到手机网站 – L2C
您误解了TPrintDialog的用途。它只是配置打印机选项;它不处理实际打印的任务。如果你需要的不是TForm.Print的默认行为,你需要自己编写代码。矩形的正确值是左+宽,就像底部是顶部+高度一样。 –