Disable Windows Close Button

  • Thread starter Thread starter Saurabh Sharma
  • Start date Start date
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
 
What about something like this:

private void Form1_Closing(object sender,
System.ComponentModel.CancelEventArgs e)
{
e.Cancel = true;
}
 
Turn off the Control menu and ALL of the window ornaments will disappear.
You will thus also lose the max, min and help buttons.
 
What about something like this:
private void Form1_Closing(object sender,
System.ComponentModel.CancelEventArgs e)
{
e.Cancel = true;
}
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
 
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.
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top