Solved

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

Posted on 2009-04-01
8
1,286 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

744 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

13 Experts available now in Live!

Get 1:1 Help Now