0

In a Delphi 10.4.2 32-bit VCLApplication, I RESIZE a TPanel (align = alClient) by moving a TSplitter control with the mouse. However, the Panel could also be resized by other actions. In this scenario, I need an automatic action to be taken ONCE AFTER the resizing of the Panel has occurred. So I wrote this OnResize action:

procedure TForm1.TPanel1Resize(Sender: TObject);
begin
  CodeSite.Send('TForm1.TPanel1Resize: ');
end;

However, this OnResize event-handler randomly is called once or twice! So I need a TPanel.OnEndResize event that occurs only once. Also, a TPanel.OnStartResize event would be useful. How can I achieve this?

user1580348
  • 5,721
  • 4
  • 43
  • 105
  • In general, in situations like these, the guarantee is that the event is called *at least* once, and you are required to handle the scenario when it is called more than once. I can think of a few situations where it is actually very difficult even for a human to determine if the resizing is really finished or not. – Andreas Rejbrand May 05 '21 at 15:48
  • However, there is a trick to implement a `TForm.OnEndResize` event handler using MESSAGES (`WM_EXITSIZEMOVE`). So I hoped a similar trick using messages would help me to implement at least e.g. a `TWinControl.OnEndResize` event handler? – user1580348 May 05 '21 at 16:02
  • 1
    You could use a timer triggered from OnResize event with an interval of something like 500mS. A rapid successions of OnResize event will prevent the timer to trigger his OnTimer event. 500mS after the last OnResize, the time will finally trigger. You can consider this as the OnEndResize event. Of course, you adjust the 500mS to fit your needs. – fpiette May 05 '21 at 17:29
  • 1
    In a simple test I made (with Delphi XE7), I never got a `TPanel.OnResize` more than **once per actual resizing**. On the other hand, using the `TSplitter.OnMove` event, it triggers twice, because in `TSplitter.MouseUp` it calls both `UpdateControlSize` and `StopSizing`. Both of these calls `FOnMoved(self);` – Tom Brunberg May 05 '21 at 17:48
  • 1
    Perhaps a `OnMouseDown` and `OnMouseUp` on the `TSplitter` could act as the resize start and end signal, respecively. They are however not published so you have to make an interposer class. For the *resized by other actions* I have no suggestions as you did not specify what the actions are. – Tom Brunberg May 05 '21 at 17:48
  • 1
    I would vote for the Timer solution as is does not require extensive knowledge of why and how the panel was resized... – R. Hoek May 05 '21 at 21:05

0 Answers0