Solved

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

Posted on 2009-04-01
8
1,303 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
  • 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Different Delete Messages 7 37
Parse the OuterHTML Data in the txtfile using c# 4 48
Need to pass connection string through config 2 26
how to read json value 2 31
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

920 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now