How do I know when my control resizes?

I am creating a custom control, and I need it to be able to respond when it changes. I need old sizes and new sizes available for some calculations.

Unfortunately, the SetWidth and SetHeight methods are private to TControl but are not protected, so I cannot override them. Is there any other way to find out that my control should be resized as well as have the old size and the new size?

+3
source share
2 answers

Override the public SetBounds method. It goes into a new size, and you can use the Width and Height properties to get the current width / height.

procedure SetBounds(ALeft, ATop, AWidth, AHeight: Integer); override;
+9
source

OnResize TControl. , .

MyControl.OnResize := MyResizeEvent;

, oldsize , , .

function Myform.MyResizeEvent(Sender: TObject) ;
var

begin

  DoSomethingOnResize(OldHeight, OldWidth, (Sender as TControl).Height,(Sender as TControl).Width);
  OldHeight := (Sender as TControl).Height;
  OldWidth := (Sender as TControl).Width;

end;
-1

Source: https://habr.com/ru/post/1744587/


All Articles