i need to update items around an edit box when it changes size.
TEdit has no OnResize event.
An edit box can resize at various times, e.g.:
- changing width/height in code
- form scaled for DPI scaling
- font changed
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?
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
来源:https://stackoverflow.com/questions/1423411/delphi-how-to-know-when-a-tedit-changes-size