Author: Jonas Bilinkevicius
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:
1 unit Unit1;
2
3 interface
4
5 uses
6 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
7 StdCtrls;
8
9 type
10 TForm1 = class(TForm)
11 ListBox1: TListBox;
12 private
13 { Private declarations }
14 FSizing: Boolean;
15 procedure WMEnterSizeMove(var AMessage: TMessage); message WM_ENTERSIZEMOVE;
16 procedure WMExitSizeMove(var AMessage: TMessage); message WM_EXITSIZEMOVE;
17 { procedure WMSize(var AMessage: TMessage); message WM_SIZE; }
18 procedure WMSysCommand(var AMessage: TMessage); message WM_SYSCOMMAND;
19 public
20 { Public declarations }
21 end;
22
23 var
24 Form1: TForm1;
25
26 implementation
27
28 {$R *.DFM}
29
30 procedure TForm1.WMSysCommand(var AMessage: TMessage);
31 begin
32 if (AMessage.WParam and $FFF0) = SC_SIZE then
33 begin
34 FSizing := true;
35 ListBox1.Items.Add(Format('SysCommand called - message: %d:%d',
36 [AMessage.WParam, AMessage.LParam]));
37 end;
38 inherited; {Note: inherited after testing for SC_SIZE}
39 end;
40
41 procedure TForm1.WMExitSizeMove(var AMessage: TMessage);
42 begin
43 inherited;
44 ListBox1.Items.Add(Format('ExitSizeMove called - message: %d:%d',
45 [AMessage.WParam, AMessage.LParam]));
46 if FSizing then
47 begin
48 {Do your stuff here}
49 FSizing := false;
50 end;
51 end;
52
53 procedure TForm1.WMEnterSizeMove(var AMessage: TMessage);
54 begin
55 inherited;
56 ListBox1.Items.Add(Format('EnterSizeMove called - message: %d:%d',
57 [AMessage.WParam, AMessage.LParam]));
58 end;
59
60 {
61 procedure TForm1.WMSize(var AMessage: TMessage);
62 begin
63 inherited;
64 ListBox1.Items.Add(Format('Size called - message: %d:%d', [AMessage.WParam,
65 AMessage.LParam]));
66 FSizing := true;
67 end;
68 }
69
70 end.
|