PDA

Click to See Complete Forum and Search --> : Disable Close Button and Prevent Form Being Moved


jmcilhinney
Oct 29th, 2008, 01:11 AM
VB version here (http://www.vbforums.com/showthread.php?t=351533).

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:public partial class Form1 : Form
{
SystemMenuManager menuManager;

public Form1()
{
InitializeComponent();

// Remove the Move menu item.
this.menuManager = new SystemMenuManager(this, false);
}
}public partial class Form1 : Form
{
SystemMenuManager menuManager;

public Form1()
{
InitializeComponent();

// Remove the Close menu item.
this.menuManager = new SystemMenuManager(this, SystemMenuManager.MenuItemState.Removed);
}
}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: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
Jan 8th, 2009, 06:28 AM
The FormImmobiliser class has been updated to make the code simpler and address a few issues with the old code.

chat2learn
Jan 23rd, 2010, 06:15 AM
look here for a very easy solution for this issue.

http://www.php24hours.com/c-sharp-how-to-disable-the-close-button-t164.html

Best regards

Nightwalker83
Feb 9th, 2010, 03:54 AM
Cool! This code could come in handy.

jmcilhinney
Feb 9th, 2010, 03:58 AM
look here for a very easy solution for this issue.

http://www.php24hours.com/c-sharp-how-to-disable-the-close-button-t164.html

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