Delphi: How to know when a TEdit changes size?

孤街浪徒 提交于 2019-12-04 12:28:40

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;

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.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!