Page 1 of 1

TCheckBox in RichView

Posted: Wed Dec 12, 2007 3:46 pm
by BernhardRoos
I've post my problem here, too (in the private newsgroup I get no answer). But I'm working the whole day on this problem without success. And now I have no ideas anymore.

All what I want is to put Checkboxes with the Editor in a Richview Component which then should print or show in the Preview.

In the editor I only use InserControl.
The TCheckbox I have registered with RegisterControl(TCheckBox).

If I execute the report (the report has a Component tppRichView and the tppRichView has the Checkbox into) then the place is empty where the Checkbox should be print.

If I set the Checkbox with the editor in another color (for example black) then I see in the preview a black rectangle.

I'm using Delphi 2007.

What do I am wrong? Where can I find an example (without ScaleRichview, I must solve it with the normal TRichView Component).

Best wishes
Bernhard

Posted: Wed Dec 12, 2007 4:01 pm
by Sergey Tkachenko
Not all controls can be printed by default TRichView printing procedure.
If some controls are not printed, use OnPrintComponent event.
For checkboxes:

Code: Select all

procedure TForm1.RVPrint1PrintComponent(Sender: TCustomRVPrint; 
  PrintMe: TControl; var ComponentImage: TBitmap); 
var r: TRect; 
    State: Cardinal; 
begin 
  if PrintMe is TCheckBox then begin 
    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; 
end;

Posted: Wed Dec 12, 2007 5:31 pm
by BernhardRoos
Thanks for the answer. I've tried OnComponentPrint. But I'm not sure if I've assigned it correct because the debugger shows me it never receives this event. Where have I set this event (for which component or classes).
Have I set this event for each Item?
Can I have an example where I can assign this event?
Best wishes
Bernhard

Posted: Thu Dec 13, 2007 7:26 am
by BernhardRoos
In the Preview which is implemented in the ActionTest Demo I can RVPrint1 use to assign the Event OnComponentPrint.
But how can I do this if I use the Print/Preview of the Reportbuilder (using ppRichView.pas). There is a property Helper and Helper has a Property RichView and this has a property RVPrint, but RVPrint is nil. If I set RVPrint to a component TRVPrint and assign the OnComponentPrint, then nothing happens. The debugger shows me that this event never is executed.
How can I use the OnComponentPrint?
Best wishes
Bernhard

Posted: Thu Dec 13, 2007 7:35 am
by BernhardRoos
The debugger shows me further :

in RVItem.pas in TRVControlItemInfo.PrintingToBitmap in line 2266 the condition (RichView is TPrintableRV) is false. So the OnPrintComponent is not executed. What can I do that RichView is from type TPrintableRV?
And where can I assign the OnPrintComponent.