我需要在更改大小时更新编辑框周围的项目。
TEdit没有 OnResize 事件。
编辑框可以在不同时间调整大小,例如:
我确信其他人我不知道。
我需要一个单独的事件才能知道编辑框何时更改了它的大小。是否有Windows消息我可以为编辑框子类化并抓取?
答案 0 :(得分: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;
答案 1 :(得分: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.
答案 2 :(得分:1)
处理wm_Size
消息。通过为其WindowProc
属性分配新值来对控件进行子类化;请务必存储旧值,以便您可以在那里委派其他消息。
另请参阅:wm_WindowPosChanged