A Delphi Custom Control: A TRichEdit with a TLabel Above It

Posted by doubleu on Stack Overflow See other posts from Stack Overflow or by doubleu
Published on 2010-06-15T15:31:51Z Indexed on 2010/06/15 15:42 UTC
Read the original article Hit count: 214

Filed under:
|

Hello, I want to create an custom control (descendant of TRichEdit). I simply want add some text above the editfield.

I've created my own control and I override the constructor to create a TLabel for the caption. It works, but my problem: How is it possible to move the label above the richedit? When I set Top := -5 the label begins to disappaer.

Here's the code of the constructor:

constructor TDBRichEditExt.Create(AOwner: TComponent);
begin
  inherited;
  lblCaption := TLabel.Create(self);
  lblCaption.Parent := parent;
  lblCaption.Caption := 'Header';
  lblCaption.Top := -5;
end;

I think it's logic that the label disappaers since the richedit is the parent. I've tried

lblCaption.Parent := self.parent;

To make the form which owns the richedit the parent - but this dosn't work...

How could I achieve this? Thank you all!

© Stack Overflow or respective owner

Related posts about delphi

Related posts about controls