Disabling of Close Form option
-
How to disable Form close option (X Box).
Truth Is The Simplest !!!!
-
How to disable Form close option (X Box).
Truth Is The Simplest !!!!
Handle the Closing event? But, really, other than asking "Are you sure?" you should allow the user to close the application.
-
How to disable Form close option (X Box).
Truth Is The Simplest !!!!
Why not just remove it ? You can do that in the form properties in the designer
Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
Why not just remove it ? You can do that in the form properties in the designer
Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
ThankXXX..Christian Yes i want to remove but there is no property available. If it is there pls let me know.
Truth Is The Simplest !!!!
-
ThankXXX..Christian Yes i want to remove but there is no property available. If it is there pls let me know.
Truth Is The Simplest !!!!
It's the 'Control Box' option.
Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
-
ThankXXX..Christian Yes i want to remove but there is no property available. If it is there pls let me know.
Truth Is The Simplest !!!!
Removing the control box gets rid of minimize and maximize too. This method just disables the close button and the Close menu item in the form's context menu. Make sure that you give the user a clean way to close the form though!
public Form1()
{
InitializeComponent();
EnableMenuItem(GetSystemMenu(this.Handle, false), SC_CLOSE, MF_GRAYED);
}
private const int SC_CLOSE = 0xf060;
private const int MF_GRAYED = 0x0001;
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern int EnableMenuItem(IntPtr hMenu, int uIDEnableItem, int uEnable);Edit: I should add - to enable it again if you need to declare this constant:
private const int MF_ENABLED = 0x0000;
and the code to perform the enable is:
EnableMenuItem(GetSystemMenu(this.Handle, false), SC_CLOSE, MF_ENABLED);
Dave
modified on Friday, February 22, 2008 6:14 AM
-
Removing the control box gets rid of minimize and maximize too. This method just disables the close button and the Close menu item in the form's context menu. Make sure that you give the user a clean way to close the form though!
public Form1()
{
InitializeComponent();
EnableMenuItem(GetSystemMenu(this.Handle, false), SC_CLOSE, MF_GRAYED);
}
private const int SC_CLOSE = 0xf060;
private const int MF_GRAYED = 0x0001;
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern int EnableMenuItem(IntPtr hMenu, int uIDEnableItem, int uEnable);Edit: I should add - to enable it again if you need to declare this constant:
private const int MF_ENABLED = 0x0000;
and the code to perform the enable is:
EnableMenuItem(GetSystemMenu(this.Handle, false), SC_CLOSE, MF_ENABLED);
Dave
modified on Friday, February 22, 2008 6:14 AM
Just tested it; it works, but Alt+F4 still closes the form.
-
Just tested it; it works, but Alt+F4 still closes the form.
Forgot that one! The code below handles that :-D
private const int WM_SYSKEYDOWN = 0x0104;
private bool handleAltF4 = true;
protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData)
{
if (msg.Msg == WM_SYSKEYDOWN)
{
switch (keyData)
{
case System.Windows.Forms.Keys.Alt | System.Windows.Forms.Keys.F4:
{
return handleAltF4;
}
}
}
// process all others as normal
return false;
}Dave
-
Forgot that one! The code below handles that :-D
private const int WM_SYSKEYDOWN = 0x0104;
private bool handleAltF4 = true;
protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData)
{
if (msg.Msg == WM_SYSKEYDOWN)
{
switch (keyData)
{
case System.Windows.Forms.Keys.Alt | System.Windows.Forms.Keys.F4:
{
return handleAltF4;
}
}
}
// process all others as normal
return false;
}Dave
I finally got around to trying that, I doubt I'd ever need it, but it's good to have, thanks!