大家好,我已经找到答案了,如下,所以,我不能给各位加分,对不起了.
修改一下 VCL 的源程序,将 Forms.pas 和 Controls.pas 拷到你工程所在的目录下,
然后作以下修改:
1)Forms.pas 中修改 TCustomForm.GetFormImage 方法,如下:
function TCustomForm.GetFormImage: TBitmap;
var
OfsX, OfsY: Integer;
R: TRect;
begin
Result := TBitmap.Create;
R := ClientRect;
OfsX := 0;
OfsY := 0;
try
with HorzScrollBardo
if FCalcRange > 0 then
begin
R.Right := Range + 4;
OfsX := Position;
end;
with VertScrollBardo
if FCalcRange > 0 then
begin
R.Bottom := Range + 4;
OfsY := Position;
end;
Result.Width := R.Right;
Result.Height := R.Bottom;
Result.Canvas.Brush := Brush;
Result.Canvas.FillRect(R);
Result.Canvas.Lock;
try
if GetWindowLong(Handle, GWL_STYLE) and WS_BORDER <> 0 then
begin
Dec(OfsX);
Dec(OfsY);
end;
PaintTo(Result.Canvas.Handle, OfsX, OfsY);
finally
Result.Canvas.Unlock;
end;
except
Result.Free;
raise;
end;
end;
2、Controls.pas 中修改 TWinControl.PaintTo 方法,如下:
procedure TWinControl.PaintTo(DC: HDC;
X, Y: Integer);
var
I, EdgeFlags, BorderFlags, SaveIndex: Integer;
R: TRect;
begin
Include(FControlState, csPaintCopy);
SaveIndex := SaveDC(DC);
MoveWindowOrg(DC, X, Y);
BorderFlags := 0;
EdgeFlags := 0;
if GetWindowLong(Handle, GWL_EXSTYLE) and WS_EX_CLIENTEDGE <> 0 then
begin
EdgeFlags := EDGE_SUNKEN;
BorderFlags := BF_RECT or BF_ADJUST
end else
if GetWindowLong(Handle, GWL_STYLE) and WS_BORDER <> 0 then
begin
EdgeFlags := BDR_OUTER;
BorderFlags := BF_RECT or BF_ADJUST or BF_MONO;
end;
if BorderFlags <> 0 then
begin
GetClipBox(DC, R);
DrawEdge(DC, R, EdgeFlags, BorderFlags);
MoveWindowOrg(DC, R.Left, R.Top);
IntersectClipRect(DC, 0, 0, R.Right - R.Left, R.Bottom - R.Top);
end;
Perform(WM_ERASEBKGND, DC, 0);
Perform(WM_PAINT, DC, 0);
if FWinControls <> nil then
for I := 0 to FWinControls.Count - 1do
with TWinControl(FWinControls)do
if Visible then
PaintTo(DC, Left, Top);
RestoreDC(DC, SaveIndex);
Exclude(FControlState, csPaintCopy);
end;
存盘后退出Delphi再重新进入Delphi,TCustomForm.GetFormImage 返回的 BitMap
就包括隐藏的部分,就可以调用Form.print打印了;在Delphi5下测试通过.