[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.
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
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
Re: [1.0/1.1] disabling resize / restore button in a form
I found something that works.
this.MaximizeBox = false;
Re: [1.0/1.1] disabling resize / restore button in a form
Sorry, it should have been this:(I 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
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 :D
Re: [1.0/1.1] disabling resize / restore button in a form
Quote:
Originally Posted by penagate
Ryan always makes things over complex :D
LOL. Complex is good I'm sure that I will have need to it sometime. Thanks again ryan. :thumb: and also you too penegate :thumb:
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.