Solved

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

Posted on 2009-04-01
8
1,409 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
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

Independent Software Vendors: 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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

623 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