G
godelphi2004
Unregistered / Unconfirmed
GUEST, unregistred user!
我想打印一个窗体上的内容,在主窗体中语句如下:
PreviewFrm := TPreviewFrm.Create(Application);
PreviewFrm.SetPage;
PreviewFrm.DrawPreview;
PreviewFrm.ShowModal;
在浏览窗口里的代码如下:
procedure TPreviewFrm.SetPage;
begin
Image1.Width := FPrinter.PageWidth div 5;
Image1.Height := FPrinter.PageHeight div 5;
end;
procedure TPreviewFrm.DrawPreview;
var
PRect,Rect: TRect;
begin
PRect.Top := 0;
PRect.Left := 0;
PRect.Right := (MainFrm.ActiveMDIChild.GetFormImage.Width) div 5;
PRect.Bottom := (MainFrm.ActiveMDIChild.GetFormImage.Height) div 5;
Rect.Top := 10;
Rect.Left := 10;
Rect.Right := 10+ (MainFrm.ActiveMDIChild.GetFormImage.Width) div 5;
Rect.Bottom := 10 + (MainFrm.ActiveMDIChild.GetFormImage.Height) div 5;
Image1.Canvas.Pen.Mode := pmWhite;
Image1.Canvas.Rectangle(0,0,Image1.Width,Image1.Height);
MainFrm.ActiveMDIChild.Canvas.CopyRect(Rect,Image1.Canvas,PRect);
end;
procedure TPreviewFrm.FormCreate(Sender: TObject);
begin
ScrollBox1.Width := ClientWidth;
ScrollBox1.Height := ClientHeight;
end;
procedure TPreviewFrm.tbPrintClick(Sender: TObject);
var
Rect: TRect;
begin
Rect.Top := 10;
Rect.Left := 10;
Rect.Right := 10 + MainFrm.ActiveMDIChild.GetFormImage.Width;
Rect.Bottom := 10 + MainFrm.ActiveMDIChild.GetFormImage.Height;
FPrinter.begin
Doc;
try
FPrinter.Canvas.StretchDraw(Rect,Image1.Picture.Bitmap);
FPrinter.EndDoc;
except
FPrinter.Abort;
end;
end;
但是这个程序运行的结果是打印出来为空。是不是语句部分有错?
PreviewFrm := TPreviewFrm.Create(Application);
PreviewFrm.SetPage;
PreviewFrm.DrawPreview;
PreviewFrm.ShowModal;
在浏览窗口里的代码如下:
procedure TPreviewFrm.SetPage;
begin
Image1.Width := FPrinter.PageWidth div 5;
Image1.Height := FPrinter.PageHeight div 5;
end;
procedure TPreviewFrm.DrawPreview;
var
PRect,Rect: TRect;
begin
PRect.Top := 0;
PRect.Left := 0;
PRect.Right := (MainFrm.ActiveMDIChild.GetFormImage.Width) div 5;
PRect.Bottom := (MainFrm.ActiveMDIChild.GetFormImage.Height) div 5;
Rect.Top := 10;
Rect.Left := 10;
Rect.Right := 10+ (MainFrm.ActiveMDIChild.GetFormImage.Width) div 5;
Rect.Bottom := 10 + (MainFrm.ActiveMDIChild.GetFormImage.Height) div 5;
Image1.Canvas.Pen.Mode := pmWhite;
Image1.Canvas.Rectangle(0,0,Image1.Width,Image1.Height);
MainFrm.ActiveMDIChild.Canvas.CopyRect(Rect,Image1.Canvas,PRect);
end;
procedure TPreviewFrm.FormCreate(Sender: TObject);
begin
ScrollBox1.Width := ClientWidth;
ScrollBox1.Height := ClientHeight;
end;
procedure TPreviewFrm.tbPrintClick(Sender: TObject);
var
Rect: TRect;
begin
Rect.Top := 10;
Rect.Left := 10;
Rect.Right := 10 + MainFrm.ActiveMDIChild.GetFormImage.Width;
Rect.Bottom := 10 + MainFrm.ActiveMDIChild.GetFormImage.Height;
FPrinter.begin
Doc;
try
FPrinter.Canvas.StretchDraw(Rect,Image1.Picture.Bitmap);
FPrinter.EndDoc;
except
FPrinter.Abort;
end;
end;
但是这个程序运行的结果是打印出来为空。是不是语句部分有错?