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); } }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.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); } }
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:EDIT (8-Jan-2009): The FormImmobiliser class has been updated to make the code simpler and address a few issues with the old code.CSharp Code:
public partial class Form1 : Form { FormImmobiliser immobiliser; public Form1() { InitializeComponent(); // Prevent the form being moved. this.immobiliser = new FormImmobiliser(this); } }


Reply With Quote
