中国开发网: 论坛: 程序员情感CBD: 贴子 91148
王中王: it is...
it is usually best to compose the printout using the Printer­.Canvas methods,
that gives you optimal control over placement and also uses ­less memory (no
page-size offscreen bitmap needs to be created). If you just­ want to dump the
form itself to the printer with minimum work try the followi­ng approach.
Hoewever, it does not use the full resolution supported by t­he printer.


Print all of a forms client area, even if parts are not visi­ble:


the form will clip the output to the visible area if you try­ to output
it to a canvas using using the forms paintto method. But one­ can print
the controls on it individually and that is not clipped:


procedure TForm1.Button1Click(Sender: TObject);
var
c: TControl;
i: Integer;
topX, topY: Integer;
begin
printer.begindoc;
try
{ Scale printer to screen resolution. }
SetMapMode( printer.canvas.handle, MM_ANISOTROPIC );
SetWindowExtEx(printer.canvas.handle,
GetDeviceCaps(canvas.handle, LOGPIXELSX),
GetDeviceCaps(canvas.handle, LOGPIXELSY),
Nil);
SetViewportExtEx(printer.canvas.handle,
GetDeviceCaps(printer.canvas.handle, LOGP­IXELSX),
GetDeviceCaps(printer.canvas.handle, LOGP­IXELSY),
Nil);
topX := 10;
topY := 10;
for i:= 0 to controlcount-1 do begin
c:= controls[i];
If c Is TWinControl Then
TWinControl(c).paintto( printer.canvas.handle,
c.left + topX,
c.top + topy );
end;
finally
printer.enddoc;
end;
end;


The problem here is that this only prints TWinControl descen­dents, if
you have TLabels or TImages on the form they are not printed­. The
solution is to put everything on the form onto a single top ­level
TPanel. This panel is *not* aligned to alClient, it has its ­left and top
set to 0 and its width and height is such that all controls ­fit on it.
The code above then prints this panel unclipped and the pane­l prints any
non-TWinControls on it.


The usual caveats for PaintTo apply: not all controls will i­mplement
this method properly (a Windows limitation). Bitmaps on the ­form may not
appear on the printer if the printer is not able to print
device-dependent bitmaps for the screen.


Peter Below (TeamB) 100113.1...@compuserve.com)
No e-mail responses, please, unless explicitely requested!
http://wangzw.wordpress.com/
个性化台历、日历制作
http://shop33697570.taobao.com/

相关信息:


欢迎光临本社区,您还没有登录,不能发贴子。请在 这里登录