472,789 Members | 1,128 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,789 software developers and data experts.

disable ALT+F4

I have written a small program and I want the user to close it down solely by
clicking on a button. How can I disable the ALT+F4 method of closing the
application down?
Nov 16 '05 #1
2 28993
You should trap the Closing event of your main form. Use some boolean to
check if your button was clicked or not.

bool myButtonWasClicked = false;

private void Form1_Closing(object sender,
System.ComponentModel.CancelEventArgs e)
// Only allow closing if your button was clicked
if (!myButtonWasClicked)
e.Cancel = true;



"cashdeskmac" <ca*********@discussions.microsoft.com> wrote in message
news:B7**********************************@microsof t.com...
I have written a small program and I want the user to close it down solely
clicking on a button. How can I disable the ALT+F4 method of closing the
application down?

Nov 16 '05 #2

If you will block the form's "Closing" then you'll
have problem with killing its thread.

I've got much more "safe" proposition for you.
I have written a small program and I want the user to close it down solely by
clicking on a button. How can I disable the ALT+F4 method of closing the
application down?

You can handle "Alt+F4" KeyDown to disable it.

1. set "KeyPreview" of your form to "true"

2. add "KeyDown" handler for your form (or override "OnKeyDown" method)

private void Form1_KeyDown(object sender
, System.Windows.Forms.KeyEventArgs e) {
if( e.Alt && e.KeyCode==Keys.F4 ) {


Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: tom | last post by:
Hello, How can I disable ALT+TAB? I've already done it for ALT+F4 by trapping windows message 16 in the WndProc override of a form. Does anyone know the windows message for ALT+TAB? thanx
by: Stefan | last post by:
Hy, a have an application and i must disable the follow combination of keys: ALT+F4 ALT+TAB CTRL+ALT+DEL CTRL+ESC. For ALT+F4 i can disable the conbination with: protected override...
by: Stefan | last post by:
Hy, i have an app and i must disable this combination: ALT+F4; CTRL+ALT+DEL; CTRL+ESC;ALT+TAB like this: i find something on Internet and i can block ALT+F4 protected override...
by: Nikki | last post by:
Hi, Can anybody help me, i want to prevent windows to close my winform of ..NET application, when user presses Alt+F4
by: Michael Maes | last post by:
Hello, ALT+F4 is the shortcut to close a form. When I use this shortcut in an MDI enviroment, the application is closed, so obviously the shortcut applies to the 'Container' and not to the...
by: Clive Poyner | last post by:
Can somebody please tell me how to disable Alt-F4 in VB.Net to prevent users from closing forms?
by: Richard Lewis Haggard | last post by:
Is there an easy way to disable the hotkey sequence Control F4 or otherwise prevent the action from killing off MDI child windows in VS05/WinForms 2? I've already figured out how to get rid of the...
by: freelancex | last post by:
Hi, Im new to this forum, and new to scripting in general. Im an ICT Technician for a high school and i am designing a Form in visual basic 2005. The intended purpose of the Form, is to prevent...
by: priya8014 | last post by:
can some one help me to disable alt+f4 using vb.net i have a code to disable alt+f4 using vb6.i did convert it to vb.net .how ever code is showing some error which i am not able to fix it . if any...
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
by: lllomh | last post by:
How does React native implement an English player?
by: Mushico | last post by:
How to calculate date of retirement from date of birth

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.