uses printers;
procedure TForm1.PrintPanel(Panel: TPanel; SLeft, STop, SWidth, SHeight, Left, Top: LongInt;
HScale, ZScale: Real);
var
WJDC: HDC;
WJBitMap: TBitMap;
Info: PBitMapInfo;
InfoSize, ImageSize: DWORD;
Image: Pointer;
begin
Printer.BeginDoc; WJBitMap := TBitMap.Create;
WJBitMap.Width := SWidth;
WJBitMap.Height := SHeight; WJDC := GetDC(Panel.Handle);
BitBlt(WJBitMap.Canvas.Handle, 0, 0, SWidth, SHeight, WJDC, SLeft, STop, SRCCOPY);
ReleaseDC(Panel.Handle, WJDC); GetDIBSizes(WJBitMap.Handle, InfoSize, ImageSize);
GetMem(Info, InfoSize);
GetMem(Image, ImageSize);
GetDIB(WJBitMap.Handle, 0, Info^, Image^); StretchDIBits(Printer.Canvas.Handle, Left, Top, Round((Panel.Width - 2) * HScale),
Round((Panel.Height - 2) * ZScale), 0, 0, Info^.bmiHeader.biWidth,
Info^.bmiHeader.biHeight, Image, Info^, DIB_RGB_COLORS, SRCCOPY);
FreeMem(Image, ImageSize);
FreeMem(Info, InfoSize);
WJBitMap.Free;
Printer.EndDoc;
end;
把一个panel和里面所包括控见所显示的都打印出来。
procedure TForm1.PrintPanel(Panel: TPanel; SLeft, STop, SWidth, SHeight, Left, Top: LongInt;
HScale, ZScale: Real);
var
WJDC: HDC;
WJBitMap: TBitMap;
Info: PBitMapInfo;
InfoSize, ImageSize: DWORD;
Image: Pointer;
begin
Printer.BeginDoc; WJBitMap := TBitMap.Create;
WJBitMap.Width := SWidth;
WJBitMap.Height := SHeight; WJDC := GetDC(Panel.Handle);
BitBlt(WJBitMap.Canvas.Handle, 0, 0, SWidth, SHeight, WJDC, SLeft, STop, SRCCOPY);
ReleaseDC(Panel.Handle, WJDC); GetDIBSizes(WJBitMap.Handle, InfoSize, ImageSize);
GetMem(Info, InfoSize);
GetMem(Image, ImageSize);
GetDIB(WJBitMap.Handle, 0, Info^, Image^); StretchDIBits(Printer.Canvas.Handle, Left, Top, Round((Panel.Width - 2) * HScale),
Round((Panel.Height - 2) * ZScale), 0, 0, Info^.bmiHeader.biWidth,
Info^.bmiHeader.biHeight, Image, Info^, DIB_RGB_COLORS, SRCCOPY);
FreeMem(Image, ImageSize);
FreeMem(Info, InfoSize);
WJBitMap.Free;
Printer.EndDoc;
end;
把一个panel和里面所包括控见所显示的都打印出来。
panel1.PaintTo(Printer.Canvas,1,1);
Printer.EndDoc;