Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Disable Windows Close Button

0 views
Skip to first unread message

Saurabh Sharma

unread,
Jan 24, 2005, 1:00:43 PM1/24/05
to
Hi
How do i disable windows close button in forms in C#

Regards
Saurabh


Ranjan

unread,
Jan 24, 2005, 1:05:07 PM1/24/05
to
Actually, you cannot disable it. What you can do is, place an image over the
button to hide it ( and do nothing when the image is clicked)

Ranjan
--
http://dotnetjunkies.com/weblog/dotnut


"Saurabh Sharma" <saurab...@yahoo.com> wrote in message
news:#b2tB7jA...@tk2msftngp13.phx.gbl...

dwight0

unread,
Jan 24, 2005, 9:55:37 PM1/24/05
to
What about something like this:

private void Form1_Closing(object sender,
System.ComponentModel.CancelEventArgs e)
{
e.Cancel = true;
}

Peter Wone

unread,
Jan 25, 2005, 12:48:58 AM1/25/05
to
Turn off the Control menu and ALL of the window ornaments will disappear.
You will thus also lose the max, min and help buttons.


Saurabh Sharma

unread,
Jan 25, 2005, 3:39:43 AM1/25/05
to
This will not allow form to close form any other source also. Well i can
assign a bool when form is closed from other source but that is fixing and
not the sloution ...
In Vb it is possible to disable the close button .... isnt there anything
like that in C#

Regards
Saurabh


dwight0

unread,
Jan 25, 2005, 6:28:59 PM1/25/05
to
You said the same thing I was thinking of when you mentioned the bool.
You also might be able to test the value of the sender and compare it
to something to see where it came from and decide what to do. I cant
think of anything thats just a single click. You would think something
that simple would be in there. Keep us updated.

Aleksandar

unread,
Feb 23, 2005, 10:25:42 AM2/23/05
to
Hello

[DllImport("user32.dll")]
private static extern int GetSystemMenu(int hwnd, int revert);

[DllImport("user32.dll")]
private static extern int GetMenuItemCount(int menu);

[DllImport("user32.dll")]
private static extern int RemoveMenu(int menu, int position, int flags);

protected void DisableCloseButton()
{
int menu = GetSystemMenu(Handle.ToInt32(), 0);
int count = GetMenuItemCount(menu);
RemoveMenu(menu, count - 1, MF_DISABLED | MF_BYPOSITION);
}

Aleksandar

"Saurabh Sharma" <saurab...@yahoo.com> wrote in message

news:%23b2tB7j...@tk2msftngp13.phx.gbl...

0 new messages