Solved

How do I implements ESC key to exit the MessageBox dialog C#

Posted on 2009-04-01
8
1,351 Views
Last Modified: 2012-05-06
Hello,

I'm trying to implement the code that when I press the ESC key in a MessageBox dialog C#, that action close the dialog box, but I don't know how I do this.

Moreover, the form is inherited of another form, and I have the method that calls the MessageBox in the "base" form.

Any idea?
0
Comment
Question by:ReaL10
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 24036819
Can you show some code, because I thought that if you press the escape-key, the dialog box will be closed with the cancel as argument
0
 

Author Comment

by:ReaL10
ID: 24036877
I have the MessageBox calls in a class where I have differents functions to call some MessageBox of the application, and I call this function in a method in the "upper" form, because my form is inherited.

I don't have an special code.
0
 

Author Comment

by:ReaL10
ID: 24036904
The MessageBox is to delete a register, and it has "Yes" and "No" buttons, but it hasn't a "Cancel" button.

Could it be that this doesn't work for the ESC key?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 53

Accepted Solution

by:
Dhaest earned 500 total points
ID: 24036917
That's correct.
From msdn: If a message box has a Cancel button, the function returns the IDCANCEL value if either the ESC key is pressed or the Cancel button is selected. If the message box has no Cancel button, pressing ESC has no effect.

0
 

Author Comment

by:ReaL10
ID: 24036938
But... There any way to implement the "No" MessageBox button for to have the ESC pressing effect without "Cancel" button?
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 24037799
It's possible, but than you'll have to override the messagebox-class (which is not that simple).
Another approach is to create a form (that looks like a messagebox), and cath the keypress-event on that form...
0
 

Author Comment

by:ReaL10
ID: 24038661
I think it's more easy to put the Cancel button in the MessageBox.

Thanks.
0
 

Author Comment

by:ReaL10
ID: 24038675
I put B and "partially" because I don't know what I had to put.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question