473,386 Members | 1,758 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 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 29253
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;
}

HTH

Yves

"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
by
clicking on a button. How can I disable the ALT+F4 method of closing the
application down?

Nov 16 '05 #2
Hi!

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 ) {
e.Handled=true;
}
}

Cheers!

Marcin
Nov 16 '05 #3

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

Similar topics

1
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
0
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...
3
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...
7
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
7
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...
1
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?
3
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...
5
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...
1
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.