Imprimir componente

Delphi

11/11/2003

Pessoal algum tem alguma rotina para imprimir um componente, ou seja, sem usar Quick Report. Por exemplo, posso imprimir um TButton ou um TDBGrid.

Agradeço a atenção.


Lfernandos

Lfernandos

Curtidas 0

Respostas

Beppe

Beppe

11/11/2003

Não tentei, mas isto deve funcionar:
procedure PrintSomeControl(Control: TControl; X, Y: Integer);
var
  R: TRect;
begin
  Assert((Control is TWinControl) or (Control is TGraphicControl), ´Controle inválido´);
  with Printer do
  begin
    BeginDoc;
    try
      if Control is TWinControl then
        TWinControl(Control).PaintTo(Canvas, 0, 0)
      else if Control is TGraphicControl then
        CopyRect(Bounds(X, Y, Control.Width, Control.Height),
          TGraphicControl(Control).Canvas,
          Rect(0, 0, Control.Width, Control.Height));
    finally
      EndDoc;
    end;
  end;
end;



GOSTEI 0
POSTAR