Link to home
Start Free TrialLog in
Avatar of eabell
eabell

asked on

Canvas Property on TRichedit??

Hello everyone,

I want to add Canvas property
in TRichedit. I tried by creating
a new component, inheriting from
TRichedit, then when i added the
canvas property, i get the message:
"not in the Base class..." during
compilation.
Please help me.

Thanks in advance.
eabell
ASKER CERTIFIED SOLUTION
Avatar of kotik
kotik

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of eabell
eabell

ASKER

Thanks..it works!
Here is the whole program,  there are of coarse better ways you could impliment this
but this should give you a good idea on how it works

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

{Customized scrollbox}

type
  TMyScrollBox = class(TScrollBox)
  private
    Canvas : TCanvas;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
  end;


{normal stuff}
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure FormActivate(Sender: TObject);
  private
    { Private declarations }
    ScrollBox: TMyScrollBox;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

{ TMyScrollBox }

constructor TMyScrollBox.Create(AOwner: TComponent);
begin
  Inherited Create(AOwner);
  Canvas := TControlCanvas.Create;
  TControlCanvas(Canvas).Control := self;
end;

destructor TMyScrollBox.Destroy;
begin
  Canvas.Free;
  inherited Destroy;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  with Scrollbox do
  begin
    left := 0;
    top := 0;
    Width := 100;
    Height := 100;
    Parent := Form1;
    Show;
  end;

  Scrollbox.Canvas.Pen.Color := clRed;
  Scrollbox.Canvas.MoveTo(0, Scrollbox.Height div 2);
  Scrollbox.Canvas.LineTo(Scrollbox.Width, Scrollbox.Height div 2);

end;

procedure TForm1.FormActivate(Sender: TObject);
begin
  Scrollbox := TMyScrollBox.Create(form1);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  Scrollbox.Destroy;
end;


end.