Click here to Skip to main content
12,554,623 members (55,810 online)
Click here to Skip to main content
Add your own
alternative version


19 bookmarked

Immoveable Form

, 16 Mar 2005
Rate this:
Please Sign up or sign in to vote.
How to create a form which cannot be repositioned by the end user.


In Visual Basic 6, a form had a Moveable property. In the .NET Framework, this property no longer exists. This was possibly removed because restricting a user from moving a form is considered a bad UI design or maybe they just didn't get around to it. Regardless of whether it is a good idea to do something or not, I believe it should at least be possible.


My personal, and potentially controversial, reason for needing this feature is that I like most applications on my PC to fill the screen. Unfortunately, too often the developer has coded the application to remember its size and position but not whether it was last maximized or not. As such I have developed the habit of resizing a window to fill the screen without maximizing it. This, maybe bad, habit has found its way into some of the software I have developed. I often size the main window of an application to fill the screen working area but unlike a maximized window, an accidental click and drag can move the window out of place and putting back is a hassle.

I use a .NET class library that I have developed with a class that inherits from System.Windows.Forms.Form and includes all the extra behaviour that I ever use in any application I build. I have extracted the code snippets responsible for implementing the Moveable property so that you can easily integrate it into any existing code you have without needing to inherit from my class.

Using the code

Whether you inherit from an extended form or you paste the code directly into a form with the rest of your code, it is very easy to use. Simply set the Moveable to False to disable both mouse dragging and the Move option on the system menu. Ideally you would set this in the Sub New method or in the Load event. You can set the property with the form designer too. The code is designed so that you can toggle the Moveable property at any point during run-time.

Friend Class Form1
    Inherits ImmoveableForm
    Public Sub New()
        'This call is required by the Windows Form Designer.
        'Add any initialization after the InitializeComponent() call
        'This disables the user's ability to move this form
        Me.Moveable = False
    End Sub
    'usual Visual Studio designer code here
End Class

Points of Interest

The resulting code for the ImmoveableForm is really quite simple as you can see in the source. Unfortunately for me, reaching this stage was not quite so straightforward. I have never written a Windows application in C/C++ or any language that requires accessing the Windows API directly so I spent a lot of time wading through the mass of API documentation provided by the MSDN Library. Once I had discovered that the only reliable way to achieve an immoveable form was to intercept window messages I was on my way to serious progress.

Disabling dragging the window caption was quite straightforward, as was ignoring selection of the Move item on the system menu. Actually preventing a selection of the Move menu item in the first place was interesting. My first thought was to delete the Move menu item from the system menu but the Windows standard tends to be greying and disabling menu items. Deleting also makes it difficult to restore the menu when the Moveable property changes from False to True without disturbing any other potential system menu changes made by this class or a subclass.

There were some problems with setting the Move menu item to disabled from within Moveable property handler. The call to disable the menu seemed to be completely ignored and a quick Google confirmed that I wasn't the only person having trouble with this. In the end I found that the answer was to trap the WM_INITMENUPOPUP window message for the system menu and make the call to disable the Move menu there. It took a while to find the documentation for the WM_INITMENUPOPUP message because it is oddly located under Keyboard Accelerators section in the Platform SDK documentation rather than the Menus section.


  • 16/03/2005
    • First release.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Jason Stangroome
Engineer Squixa
Australia Australia
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralMy vote of 5 Pin
3AgL3 DeeJay1-Sep-14 12:38
member3AgL3 DeeJay1-Sep-14 12:38 
GeneralAwesome! Pin
3AgL3 DeeJay1-Sep-14 12:37
member3AgL3 DeeJay1-Sep-14 12:37 
QuestionDo we really need this while we have LocationChanged event. Pin
Uma Shankar Patel12-Apr-12 21:20
memberUma Shankar Patel12-Apr-12 21:20 
Questionnot working for me Pin
noemailz10-Jan-07 4:06
membernoemailz10-Jan-07 4:06 
AnswerRe: not working for me Pin
noemailz10-Jan-07 4:17
membernoemailz10-Jan-07 4:17 
GeneralHelped me out big time! Pin
jgags18-Oct-06 5:17
memberjgags18-Oct-06 5:17 
GeneralThis worked okay for me BUT.... Pin
Layston28-Aug-06 5:40
memberLayston28-Aug-06 5:40 
GeneralRe: This worked okay for me BUT.... Pin
Avanost25-Mar-07 3:47
memberAvanost25-Mar-07 3:47 
GeneralC# code Pin
syncter23-Oct-05 4:54
membersyncter23-Oct-05 4:54 
GeneralGreat..... Pin
Amol Srawde28-Jun-05 19:01
memberAmol Srawde28-Jun-05 19:01 
GeneralForcing users... Pin
StealthyMark16-Mar-05 0:42
memberStealthyMark16-Mar-05 0:42 
GeneralRe: Forcing users... Pin
Ashaman16-Mar-05 1:44
memberAshaman16-Mar-05 1:44 
GeneralRe: Forcing users... Pin
Jason Stangroome16-Mar-05 11:13
memberJason Stangroome16-Mar-05 11:13 
GeneralRe: Forcing users... Pin
Ashaman17-Mar-05 6:55
memberAshaman17-Mar-05 6:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161021.1 | Last Updated 16 Mar 2005
Article Copyright 2005 by Jason Stangroome
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid