Results 1 to 5 of 5

Thread: Disable Close Button and Prevent Form Being Moved

  1. #1

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Disable Close Button and Prevent Form Being Moved

    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:
    1. public partial class Form1 : Form
    2. {
    3.     SystemMenuManager menuManager;
    4.  
    5.     public Form1()
    6.     {
    7.         InitializeComponent();
    8.  
    9.         // Remove the Move menu item.
    10.         this.menuManager = new SystemMenuManager(this, false);
    11.     }
    12. }
    CSharp Code:
    1. public partial class Form1 : Form
    2. {
    3.     SystemMenuManager menuManager;
    4.  
    5.     public Form1()
    6.     {
    7.         InitializeComponent();
    8.  
    9.         // Remove the Close menu item.
    10.         this.menuManager = new SystemMenuManager(this, SystemMenuManager.MenuItemState.Removed);
    11.     }
    12. }
    CSharp Code:
    1. public partial class Form1 : Form
    2. {
    3.     SystemMenuManager menuManager;
    4.  
    5.     public Form1()
    6.     {
    7.         InitializeComponent();
    8.  
    9.         // Remove the Move menu item and grey out the Close menu item.
    10.         this.menuManager = new SystemMenuManager(this, false, SystemMenuManager.MenuItemState.Greyed);
    11.     }
    12. }
    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:
    1. public partial class Form1 : Form
    2. {
    3.     FormImmobiliser immobiliser;
    4.  
    5.     public Form1()
    6.     {
    7.         InitializeComponent();
    8.  
    9.         // Prevent the form being moved.
    10.         this.immobiliser = new FormImmobiliser(this);
    11.     }
    12. }
    EDIT (8-Jan-2009): The FormImmobiliser class has been updated to make the code simpler and address a few issues with the old code.
    Attached Files Attached Files
    Last edited by jmcilhinney; Jan 8th, 2009 at 07:28 AM.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  2. #2

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Disable Close Button and Prevent Form Being Moved

    The FormImmobiliser class has been updated to make the code simpler and address a few issues with the old code.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    New Member
    Join Date
    Jan 2010
    Posts
    1

    Re: Disable Close Button and Prevent Form Being Moved

    look here for a very easy solution for this issue.

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

    Best regards

  4. #4
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Disable Close Button and Prevent Form Being Moved

    Cool! This code could come in handy.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  5. #5

    Thread Starter
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Disable Close Button and Prevent Form Being Moved

    Quote Originally Posted by chat2learn View Post
    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width