Uncloseable window
-
Hi, I have a modal dialog that I don't want the user to close via the close button, how do I disable it? Thanks
-
Override the OnClosing event and set the Cancel memeber of that event argument to true. Rember that just disabling close button won't do the job, user can still use ALT + F4 :) . Stevo
-
Hi, I have a modal dialog that I don't want the user to close via the close button, how do I disable it? Thanks
He you can do it by 2 methods, First one is just capture closing event of that form and make e.cancel = true; or second method is you disable closing button using following code, You have to use win32 dll.
const int SC_CLOSE = 0xF060; const int MF_BYCOMMAND = 0x0; [System.Runtime.InteropServices.DllImport("user32.dll")] public static extern IntPtr RemoveMenu(IntPtr menuHwnd, int position, int flags ); [System.Runtime.InteropServices.DllImport("user32.dll")] public static extern IntPtr GetSystemMenu(IntPtr hwnd, int bRevert); public static void EnableApplicationClose( System.Windows.Forms.Form form, bool val ) { IntPtr menu = GetSystemMenu( form.Handle, val ? 1 : 0 ); if ( !val && menu != IntPtr.Zero ) RemoveMenu(menu, SC_CLOSE, MF_BYCOMMAND ); else { // needed when enabling the app close box to force it to redraw. form.Enabled = false; form.Enabled = true; } }
Rahul Kulkarni -
He you can do it by 2 methods, First one is just capture closing event of that form and make e.cancel = true; or second method is you disable closing button using following code, You have to use win32 dll.
const int SC_CLOSE = 0xF060; const int MF_BYCOMMAND = 0x0; [System.Runtime.InteropServices.DllImport("user32.dll")] public static extern IntPtr RemoveMenu(IntPtr menuHwnd, int position, int flags ); [System.Runtime.InteropServices.DllImport("user32.dll")] public static extern IntPtr GetSystemMenu(IntPtr hwnd, int bRevert); public static void EnableApplicationClose( System.Windows.Forms.Form form, bool val ) { IntPtr menu = GetSystemMenu( form.Handle, val ? 1 : 0 ); if ( !val && menu != IntPtr.Zero ) RemoveMenu(menu, SC_CLOSE, MF_BYCOMMAND ); else { // needed when enabling the app close box to force it to redraw. form.Enabled = false; form.Enabled = true; } }
Rahul Kulkarni -
Hi, I have a modal dialog that I don't want the user to close via the close button, how do I disable it? Thanks
Choose a window style without close button: FormBorderStyle.None Having a button (or any GUI element) visible but turned off (without a visual clue) is not good practice. :)
Luc Pattyn [My Articles] [Forum Guidelines]
-
Choose a window style without close button: FormBorderStyle.None Having a button (or any GUI element) visible but turned off (without a visual clue) is not good practice. :)
Luc Pattyn [My Articles] [Forum Guidelines]
Luc Pattyn wrote:
Having a button (or any GUI element) visible but turned off (without a visual clue) is not good practice.
Yup! The entity that can not be used drives the user mad. :mad: :)
Vasudevan Deepak Kumar Personal Homepage Tech Gossips
-
Luc Pattyn wrote:
Having a button (or any GUI element) visible but turned off (without a visual clue) is not good practice.
Yup! The entity that can not be used drives the user mad. :mad: :)
Vasudevan Deepak Kumar Personal Homepage Tech Gossips
and the dialog that can't be closed drives the user to kill process and uninstall. :mad: X|
-- You have to explain to them [VB coders] what you mean by "typed". their first response is likely to be something like, "Of course my code is typed. Do you think i magically project it onto the screen with the power of my mind?" --- John Simmons / outlaw programmer