How to prevent cnt+f4 key,,,?
-
Hello experts... I am developing an game using desktop application in C#.net 2005. In that I have 3 forms (No MDI form). I want to show form1 then form2 and then form3. But if user press cntl+f4 key form goes close and second forms show how to prevent this..? I also have close button on each form.
Regards Pankaj Joshi
-
Hello experts... I am developing an game using desktop application in C#.net 2005. In that I have 3 forms (No MDI form). I want to show form1 then form2 and then form3. But if user press cntl+f4 key form goes close and second forms show how to prevent this..? I also have close button on each form.
Regards Pankaj Joshi
Handle the
Closing
event on the form, the event arguments will have aCancel
property. Set thatCancel
property totrue
.
Upcoming FREE developer events: * Glasgow: SQL Server Managed Objects AND Reporting Services ... My website
-
Hello experts... I am developing an game using desktop application in C#.net 2005. In that I have 3 forms (No MDI form). I want to show form1 then form2 and then form3. But if user press cntl+f4 key form goes close and second forms show how to prevent this..? I also have close button on each form.
Regards Pankaj Joshi
1. Set the form's KeyPreview property to true. 2. Add a KeyDown event to the form like this: private void Form1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyValue == (int)Keys.F4 && e.Modifiers == Keys.Control) { e.SuppressKeyPress = true; } } That's it. Hope it'll help. Danny
-
1. Set the form's KeyPreview property to true. 2. Add a KeyDown event to the form like this: private void Form1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyValue == (int)Keys.F4 && e.Modifiers == Keys.Control) { e.SuppressKeyPress = true; } } That's it. Hope it'll help. Danny
Hello DannyAdler sir, This is working fine. Thannks for the help. I only have one question .. Is their any problem to using that code.? I don't think so... But if any, please tell me points to be remember while using this code.
Regards Pankaj Joshi
-
Hello DannyAdler sir, This is working fine. Thannks for the help. I only have one question .. Is their any problem to using that code.? I don't think so... But if any, please tell me points to be remember while using this code.
Regards Pankaj Joshi
Two things I can think of: 1. After setting the KeyPreview property to true, ALL the key-down events will first go through this function. 2. The CTRL-F4 will never work on that window, as long as the key-down is supressed in the if statement. Just to keep in mind. Danny