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

Making a Form Non-Moveable

By , About.com Guide

Here is how to keep the window from moving:
First, make the borderstyle something like bsDialog, so that the window cant be resized.
Next, add the following declaration to your form class:
procedure PosChange(var Msg: TWmWindowPosChanging) ; message WM_WINDOWPOSCHANGING;

//Implement the message handler as:

procedure TForm1.PosChange(var Msg: TWmWindowPosChanging) ;
begin
  Msg.WindowPos.x := Left;
  Msg.WindowPos.y := Top;
  Msg.Result := 0;
end;
Thats it. Easy as can be. The only problem with this is that you cant move the form if you want your code to. To get around this, just set up a Boolean variable called PosLocked, set it to True when you want to lock the forms position, and to false when you need to move the form (when your done, remember to set it back to true). Then to implement the proc above, just make it...
if PosLocked then
begin
  Msg.WindowPos.x := Left;
  Msg.WindowPos.y := Top;
  Msg.Result := 0;
end
else
  inherited;

Delphi tips navigator:
» Execute the Windows Explorer Find File Dialog Box
« Select a block of code by column

Explore Delphi Programming
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

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

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. Delphi Tips and Tricks
  6. 1999 Delphi Tips
  7. Making a Delphi Form Non-Movable

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

All rights reserved.