Search code examples
windowsdelphieventsresizeeditbox

Delphi: How to know when a TEdit changes size?


i need to update items around an edit box when it changes size.

TEdit has no OnResize event.

An edit box can resize at various times, e.g.:

  • changing width/height in code
  • form scaled for DPI scaling
  • font changed

And i'm sure others i don't know about.

i need a single event to know when an edit box has changed its size. Is there a Windows message i can subclass the edit box for and grab?


Solution

  • OnResize is declared as a protected property of TControl. You could expose it using a so-called "cracker" class. It's a bit of a hack, though.

    type
      TControlCracker = class(TControl);
    

    ...

    procedure TForm1.FormCreate(Sender: TObject);
    begin
      TControlCracker(Edit1).OnResize := MyEditResize;
    end;
    
    procedure TForm1.MyEditResize(Sender: TObject);
    begin
      Memo1.Lines.Add(IntToStr(Edit1.Width));
    end;