1. Home
  2. Computing & Technology
  3. Delphi Programming

How to Detect the Start Move/Resize, Move and Stop Move/Resize events of a Form

By Zarko Gajic, About.com

If you want to detect when a user starts resizing and moving a Delphi form, and when the move (or resize) operation is finished, you need to handle a few Windows messages. The WM_ENTERSIZEMOVE message is sent once to a window when it enters the moving or sizing mode. The WM_EXITSIZEMOVE message is sent once to a window after it has exited the moving or sizing mode. While a form is being moved, the WM_MOVE message is sent to a window.

Here's an example (move this form and watch its title):

~~~~~~~~~~~~~~~~~~~~~~~~~
type
   TForm1 = class(TForm)
   private
     procedure WMEnterSizeMove(var Message: TMessage) ; message WM_ENTERSIZEMOVE;
     procedure WMMove(var Message: TMessage) ; message WM_MOVE;
     procedure WMExitSizeMove(var Message: TMessage) ; message WM_EXITSIZEMOVE;

...

procedure TForm1.WMEnterSizeMove(var Message: TMessage) ;
begin
   Caption := 'Move / resize started';
end; (*WMEnterSizeMove*)

procedure TForm1.WMMove(var Message: TMessage) ;
begin
   Caption := Format('Form is being moved. Client area x: %d, y:%d', [TWMMove(Message).XPos,TWMMove(Message).YPos]) ;
end; (*WMMove*)

procedure TForm1.WMExitSizeMove(var Message: TMessage) ;
begin
   ShowMessage('Move / resize complete!') ;
end; (*WMExitSizeMove*)
~~~~~~~~~~~~~~~~~~~~~~~~~

More Form related tips and article.

Delphi tips navigator:
» Delphi IDE (Code Editor) Keyboard Shortcuts
« How to Convert a Bitmap to a Cursor using Delphi code

More Delphi Programming Quick Tips
Explore Delphi Programming
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. Delphi Tips and Tricks
  6. 2005 Delphi Tips
  7. How to Detect the Start Move/Resize, Move and Stop Move/Resize events of a Delphi Form

©2009 About.com, a part of The New York Times Company.

All rights reserved.