Delphi: How do I know when TEdit resizes?

I need to update the elements around the edit window when it resizes.

TEdit does not have an OnResize event .

The edit field can resize at different times, for example:

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

And I'm sure the others that I don't know about.

I need one event to find out when the edit box changed its size. Is there a windows message that I can subclass the edit box and capture?

+3
source share
3 answers

OnResize TControl. , "". .

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;
+9

- :

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.

:

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.
+3

Handle the message wm_Size. Subclass - management, assigning a new value to its WindowProcproperty; remember to keep the old value so that you can delegate other messages there.

See also: wm_WindowPosChanged

+1
source

Source: https://habr.com/ru/post/1717681/


All Articles