3

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?

Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219

3 Answers3

9

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;
Bruce McGee
  • 15,076
  • 6
  • 55
  • 70
3

Did you try something like this:

unit _MM_Copy_Buffer_;

interface

type
  TMyEdit = class(TCustomEdit)
  protected
    procedure Resize; override;
  end;

implementation

procedure TMyEdit.Resize;
begin
  inherited;
  if not (csLoading in ComponentState) then
  begin
    // react on new size
  end;
end;

end.

or this:

unit _MM_Copy_Buffer_;

interface

type
  TCustomComboEdit = class(TCustomMaskEdit)
  private
    procedure WMSize(var Message: TWMSize); message WM_SIZE;
  end;

implementation

procedure TCustomComboEdit.WMSize(var Message: TWMSize);
begin
  inherited;
  if not (csLoading in ComponentState) then
  begin
    // react on new size
  end;
  UpdateBtnBounds;
end;

end.
Jeroen Wiert Pluimers
  • 23,965
  • 9
  • 74
  • 154
1

Handle the wm_Size message. Subclass a control by assigning a new value to its WindowProc property; be sure to store the old value so you can delegate other messages there.

See also: wm_WindowPosChanged

Rob Kennedy
  • 161,384
  • 21
  • 275
  • 467