How to prevent Alt+F4

0

007

I have a FixedToolWindow form that I create and display when the user
presses a button on the toolbar. I want to prevent Alt+F4 on the
FixedToolWindow form. How do I accomplish this? I want the only way to close
the FixedToolWindow form is by clicking on the toolbar button again.

It's a bit like pressing "Search" on IE's toolbar.

BTW why is the ToolBar that comes with VS.NET so ugly? It's like the old
style toolbar.

Thanks.
 
C

Chris R

Look at the Form.Closing event.
You can set
e.Cancel = true;
but be careful with your logic, so that you don't make it so that you cannot
close your form at all.

// Sample on how this can be done. Note that this will also prevent use of
the X button for exit.
// Only the Close button will allow this form to close.

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

private void buttonClose_Click(object sender, System.EventArgs e)
{
keepOpen = false;
this.Close();
}

Chris R.
 
J

Jon Davis

007 said:
I have a FixedToolWindow form that I create and display when the user
presses a button on the toolbar. I want to prevent Alt+F4 on the
FixedToolWindow form. How do I accomplish this? I want the only way to close
the FixedToolWindow form is by clicking on the toolbar button again.

Asking how to lock the user out from the "panic keystroke" of Alt-F4 is like
asking how to write a trojan horse. Don't do it. If you want the closure to
be handled, handle the "Closing" and/or "Closed" events on the form.
BTW why is the ToolBar that comes with VS.NET so ugly? It's like the old
style toolbar.

Use a manifest file to enable the Win98 look and feel for the taskbar,
buttons, and scrollbars.

Jon
 
J

Jon Davis

Jon Davis said:
Use a manifest file to enable the Win98 look and feel for the taskbar,
buttons, and scrollbars.

Sorry, should have read "WinXP".

Jon
 

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

Top