Mirror

Implement an OnEndResize event for a TForm (Views: 709)


Problem/Question/Abstract:

Any idea how to implement an OnEndResize event for TForm? Obviously, it should be fired when the user finishes resizing the form.

Answer:

You'll need to handle WM_SYSCOMMAND and WM_EXITSIZEMOVE. Here's a framework to get you started:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    ListBox1: TListBox;
  private
    { Private declarations }
    FSizing: Boolean;
    procedure WMEnterSizeMove(var AMessage: TMessage); message WM_ENTERSIZEMOVE;
    procedure WMExitSizeMove(var AMessage: TMessage); message WM_EXITSIZEMOVE;
    { procedure WMSize(var AMessage: TMessage); message WM_SIZE; }
    procedure WMSysCommand(var AMessage: TMessage); message WM_SYSCOMMAND;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.WMSysCommand(var AMessage: TMessage);
begin
  if (AMessage.WParam and $FFF0) = SC_SIZE then
  begin
    FSizing := true;
    ListBox1.Items.Add(Format('SysCommand called - message: %d:%d',
      [AMessage.WParam, AMessage.LParam]));
  end;
  inherited; {Note: inherited after testing for SC_SIZE}
end;

procedure TForm1.WMExitSizeMove(var AMessage: TMessage);
begin
  inherited;
  ListBox1.Items.Add(Format('ExitSizeMove called - message: %d:%d',
    [AMessage.WParam, AMessage.LParam]));
  if FSizing then
  begin
    {Do your stuff here}
    FSizing := false;
  end;
end;

procedure TForm1.WMEnterSizeMove(var AMessage: TMessage);
begin
  inherited;
  ListBox1.Items.Add(Format('EnterSizeMove called - message: %d:%d',
    [AMessage.WParam, AMessage.LParam]));
end;

{
procedure TForm1.WMSize(var AMessage: TMessage);
begin
  inherited;
  ListBox1.Items.Add(Format('Size called - message: %d:%d', [AMessage.WParam,
                                      AMessage.LParam]));
  FSizing := true;
end;
}

end.

<< Back to main page