Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2009-04-01
8
Medium Priority
?
1,466 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 53

Accepted Solution

by:
Dhaest earned 1500 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
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…

704 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