# VBForums CodeBank > CodeBank - C# >  Disable Close Button and Prevent Form Being Moved

## jmcilhinney

VB version here.

*SystemMenuManager class* - This class allows you to remove the Move menu item from a form's system menu, thus rendering the form immovable.  It also allows you to disable, grey out or remove the Close menu item from the system menu, thus disabling the Close box (red X button) on the title bar.  Usage examples:
CSharp Code:
public partial class Form1 : Form
{
    SystemMenuManager menuManager;
     public Form1()
    {
        InitializeComponent();
         // Remove the Move menu item.
        this.menuManager = new SystemMenuManager(this, false);
    }
}

CSharp Code:
public partial class Form1 : Form
{
    SystemMenuManager menuManager;
     public Form1()
    {
        InitializeComponent();
         // Remove the Close menu item.
        this.menuManager = new SystemMenuManager(this, SystemMenuManager.MenuItemState.Removed);
    }
}

CSharp Code:
public partial class Form1 : Form
{
    SystemMenuManager menuManager;
     public Form1()
    {
        InitializeComponent();
         // Remove the Move menu item and grey out the Close menu item.
        this.menuManager = new SystemMenuManager(this, false, SystemMenuManager.MenuItemState.Greyed);
    }
}
Note that the system menu is the one that appears when you click the icon in the title bar of a form or you right-click the form's button in the Task Bar.

*FormImmobiliser class* - Using the SystemMenuManager class to remove the Move menu item has no effect if the form's ControlBox property has been set to False.  The FormImmobiliser class will prevent a form being moved in all cases, though the Move menu item will still be present in the system menu and respond to clicks.  Usage example:
CSharp Code:
public partial class Form1 : Form
{
    FormImmobiliser immobiliser;
     public Form1()
    {
        InitializeComponent();
         // Prevent the form being moved.
        this.immobiliser = new FormImmobiliser(this);
    }
}
EDIT (8-Jan-2009): The FormImmobiliser class has been updated to make the code simpler and address a few issues with the old code.

----------


## jmcilhinney

The FormImmobiliser class has been updated to make the code simpler and address a few issues with the old code.

----------


## chat2learn

look here for a very easy solution for this issue. 

http://www.php24hours.com/c-sharp-ho...tton-t164.html

Best regards

----------


## Nightwalker83

Cool! This code could come in handy.

----------


## jmcilhinney

> look here for a very easy solution for this issue. 
> 
> http://www.php24hours.com/c-sharp-ho...tton-t164.html
> 
> Best regards


That's only a solution for certain situations because it removes the Minimize, Maximize and Help buttons too, as well as the system menu.

----------

