[英]Delphi: How to know when a TEdit changes size?
i need to update items around an edit box when it changes size. 我需要在更改大小时更新编辑框周围的项目。
TEdit has no OnResize event. TEdit没有OnResize事件。
An edit box can resize at various times, eg: 编辑框可以在不同时间调整大小,例如:
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?
是否有Windows消息我可以为编辑框子类化并抓取?
OnResize is declared as a protected property of TControl. OnResize被声明为TControl的受保护属性。 You could expose it using a so-called "cracker" class.
您可以使用所谓的“cracker”类来公开它。 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. 处理
wm_Size
消息。 Subclass a control by assigning a new value to its WindowProc
property; 通过为其
WindowProc
属性分配新值来对控件进行子类化; be sure to store the old value so you can delegate other messages there. 请务必存储旧值,以便您可以在其中委派其他消息。
See also: wm_WindowPosChanged
另见:
wm_WindowPosChanged
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.