[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 388
  • Last Modified:

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
0
eabell
Asked:
eabell
1 Solution
 
kotikCommented:
Hi!
I used this code to do the same thing:

TMyRichEdit = class(TRichEdit)
private
  Canvas : TCanvas;
public
  constructor Create(AOwner: TComponent); override;
  destructor Destroy; override;
end;

implementation

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

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

Regards,
Kot
0
 
eabellAuthor Commented:
Thanks..it works!
0
 
PoeticAudioCommented:
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.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now