rvico TRichView Reference | TCustomRVPrint

TCustomRVPrint.OnPrintComponent

Top  Previous  Next

Occurs when printing inserted control

property OnPrintComponent: TRVPrintComponentEvent;

 

TRVPrintComponentEvent = procedure(Sender: TCustomRVPrint;

  PrintMe: TControl; var ComponentImage: TBitmap) of object;

If you are not satisfied how RichView prints some classes of controls, you can print them yourself.

This event requests image of control, in screen resolution, in bitmap.

Input parameters:

PrintMe – the control for printing.

ComponentImagenil.

Output parameter:

ComponentImage – image of PrintMe. You should create this bitmap in this event and should not destroy it yourself (RVPrint will do it for you).

Create the bitmap having width and height of PrintMe (you can return larger bitmap and it will be stretched, allowing to create better print output).

 

There are several methods for creating bitmap for components in CtrlImage unit: DrawControl and others. The component use them for default controls printing.

Example:

procedure MyForm.MyRVPrintPrintComponent(Sender: TCustomRVPrint;

  PrintMe: TControl; var ComponentImage: TBitmap);

var r: TRect; 

    State: Cardinal

begin

  if PrintMe is TImage then begin

    // printing TImage

    ComponentImage := TBitmap.Create;

    ComponentImage.Assign(TImage(PrintMe).Picture.Graphic);

    end

  else if PrintMe is TCheckBox then begin 

    // printing TCheckBox

    ComponentImage := TBitmap.Create; 

    ComponentImage.Width := PrintMe.Width; 

    ComponentImage.Height := PrintMe.Height; 

    ComponentImage.Canvas.Brush.Color := TCheckBox(PrintMe).Color; 

    r := Rect(0,0, PrintMe.Width, PrintMe.Height); 

    ComponentImage.Canvas.FillRect(r); 

    if TCheckBox(PrintMe).Checked then 

      State := DFCS_CHECKED 

    else 

      State := 0

    r.Right := r.Bottom; 

    DrawFrameControl(ComponentImage.Canvas.Handle, r, DFC_BUTTON, 

      DFCS_BUTTONCHECK or State); 

    r := Rect(r.Right,0, PrintMe.Width, PrintMe.Height); 

    ComponentImage.Canvas.Font := TCheckBox(PrintMe).Font; 

    DrawText(ComponentImage.Canvas.Handle, PChar(' '+TCheckBox(PrintMe).Caption), -1, r, 

      DT_VCENTER or DT_SINGLELINE); 

    end

  else

    // printing other controls

    ComponentImage := DrawControl(PrintMe)

end;

In TRVPrint, this event is generated by:

Print;

PrintPages;

MakePreview;

MakeScaledPreview;

DrawPreview;

when drawing TRVPrintPreview component.


TRichView © trichview.com