Results 1 to 8 of 8

Thread: [RESOLVED] [1.0/1.1] disabling resize / restore button in a form

  1. #1

    Thread Starter
    Hyperactive Member drattansingh's Avatar
    Join Date
    Sep 2005
    Posts
    395

    Resolved [RESOLVED] [1.0/1.1] disabling resize / restore button in a form

    Hi. Is there any way to disable the resize / restore button in a sizeable form? I don't want to delete it, just disable it.
    Last edited by drattansingh; May 16th, 2006 at 12:02 PM.

  2. #2
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: [1.0/1.1] disabling resize / restore button in a form

    Well, you can modify the code found here to use the following constants:

    Code:
    const int SC_MAXIMIZE = 0xF030;
    const int SC_MINIMIZE = 0xF020;
    Cheers,

    Ryan Jones
    My Blog.

    Ryan Jones.

  3. #3

    Thread Starter
    Hyperactive Member drattansingh's Avatar
    Join Date
    Sep 2005
    Posts
    395

    Re: [1.0/1.1] disabling resize / restore button in a form

    Ok the following code disabled the close button:


    Code:
    private const int SC_CLOSE = 0xF060;
    		private const int MF_GRAYED = 0x1;
    
    		[DllImport("user32.dll")]
    		private static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
    
    		[DllImport("user32.dll")]
    		private static extern int EnableMenuItem(IntPtr hMenu, int wIDEnableItem, int wEnable);
    
    		private void Form1_Load(object sender, System.EventArgs e)
    		{
    			EnableMenuItem(GetSystemMenu(this.Handle, false), SC_CLOSE, MF_GRAYED);
    		}


    I tried appending to the following:

    Code:
    const int SC_MAXIMIZE = 0xF030;
    const int SC_MINIMIZE = 0xF020;
    
    		[DllImport("user32.dll")]
    		private static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
    
    		[DllImport("user32.dll")]
    		private static extern int EnableMenuItem(IntPtr hMenu, int wIDEnableItem, int wEnable);
    
    		private void Form1_Load(object sender, System.EventArgs e)
    		{
    			EnableMenuItem(GetSystemMenu(this.Handle, false), SC_MAXIMIZE, SC_MINIMIZE );
    		}

    I know I'm doing something wrong since it is not working, is anyone seeing what I'm diong wrong?

    Jennifer

  4. #4

    Thread Starter
    Hyperactive Member drattansingh's Avatar
    Join Date
    Sep 2005
    Posts
    395

    Re: [1.0/1.1] disabling resize / restore button in a form

    I found something that works.

    this.MaximizeBox = false;

  5. #5
    Frenzied Member sciguyryan's Avatar
    Join Date
    Sep 2003
    Location
    Wales
    Posts
    1,763

    Re: [1.0/1.1] disabling resize / restore button in a form

    Sorry, it should have been thisI think)

    Code:
    private const int MF_GRAYED = 0x1;
    private const int SC_MAXIMIZE = 0xF030;
    private const int SC_MINIMIZE = 0xF020;
    
    [DllImport("user32.dll")]
    private static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
    
    [DllImport("user32.dll")]
    private static extern int EnableMenuItem(IntPtr hMenu, int wIDEnableItem, int wEnable);
    
    private void Form1_Load(object sender, System.EventArgs e)
    {
        EnableMenuItem(GetSystemMenu(this.Handle, false), SC_MAXIMIZE, MF_GRAYED);
        EnableMenuItem(GetSystemMenu(this.Handle, false), SC_MINIMIZE, MF_GRAYED);
    }
    Cheers,

    Ryan Jones
    My Blog.

    Ryan Jones.

  6. #6
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: [1.0/1.1] disabling resize / restore button in a form

    Quote Originally Posted by JenniferBabe
    I found something that works.

    this.MaximizeBox = false;
    Ryan always makes things over complex

  7. #7

    Thread Starter
    Hyperactive Member drattansingh's Avatar
    Join Date
    Sep 2005
    Posts
    395

    Re: [1.0/1.1] disabling resize / restore button in a form

    Quote Originally Posted by penagate
    Ryan always makes things over complex

    LOL. Complex is good I'm sure that I will have need to it sometime. Thanks again ryan. and also you too penegate

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [RESOLVED] [1.0/1.1] disabling resize / restore button in a form

    Just note that setting MaximizeBox to False is all well and good but if you set MinimizeBox to False as well then both the buttons will be removed altogether, not just disabled.
    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