3

当编辑框改变大小时,我需要更新它周围的项目。

TEdit 没有OnResize事件。

编辑框可以在不同时间调整大小,例如:

  • 更改代码中的宽度/高度
  • 为 DPI 缩放而缩放的表格
  • 字体已更改

我敢肯定还有一些我不知道的人。

我需要一个事件来知道编辑框何时改变了它的大小。是否有一条 Windows 消息我可以将编辑框子类化并抓取?

4

3 回答 3

9

OnResize 被声明为 TControl 的受保护属性。您可以使用所谓的“cracker”类公开它。不过,这有点骇人听闻。

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;
于 2009-09-14T19:45:44.853 回答
3

你有没有尝试过这样的事情:

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.
于 2009-09-14T19:45:55.503 回答
1

处理wm_Size消息。通过为其WindowProc属性分配新值来子类化控件;请务必存储旧值,以便您可以在那里委派其他消息。

也可以看看:wm_WindowPosChanged

于 2009-09-14T20:31:53.637 回答