473,385 Members | 1,342 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Dialog: Cancel button / esc key (Windows forms)

WP
Hello, a short question: Do I have to add a cancel button to my form
dialog for it to be closable by the esc key? Right now I have no
cancel button in my dialog and I noticed the esc key will not close
it. First I thought the two textboxes I have in the dialog "consumed"
the esc key press but I removed them and the dialog still doesn't
close when the esc key is pressed so that was not it.

- Eric
Mar 14 '08 #1
3 10719
private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)27)
Application.Exit();
}

Uzytkownik "WP" <mi********@gmail.comnapisal w wiadomosci
news:39**********************************@i29g2000 prf.googlegroups.com...
Hello, a short question: Do I have to add a cancel button to my form
dialog for it to be closable by the esc key? Right now I have no
cancel button in my dialog and I noticed the esc key will not close
it. First I thought the two textboxes I have in the dialog "consumed"
the esc key press but I removed them and the dialog still doesn't
close when the esc key is pressed so that was not it.

- Eric
Mar 14 '08 #2
On Fri, 14 Mar 2008 14:36:51 -0700, twoj wladca <kr**@vp.plwrote:
private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)27)
Application.Exit();
}
If you are going to follow this technique, Eric (and it seems from your
other post you're not), I'd recommend handling instead the KeyDown event,
and comparing against Keys.Escape rather than the above.

Noting also, of course, that for simply closing a dialog box, calling
Application.Exit() is probably overkill. :)

Pete
Mar 14 '08 #3
WP
On 14 Mar, 23:18, "Peter Duniho" <NpOeStPe...@nnowslpianmk.comwrote:
On Fri, 14 Mar 2008 14:36:51 -0700, twoj wladca <k...@vp.plwrote:
private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)27)
Application.Exit();
}

If you are going to follow this technique, Eric (and it seems from your
other post you're not), I'd recommend handling instead the KeyDown event,
and comparing against Keys.Escape rather than the above.

Noting also, of course, that for simply closing a dialog box, calling
Application.Exit() is probably overkill. :)

Pete
No, I am not going down that road even though I appreciate people
trying to help me. But I can't help thinking that that code looks like
my very simple key handlers I wrote in pure C when doing glut-
programming. :)
Mar 14 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: jaxCtiDev | last post by:
My application is written in C# and has several dialog Windows Forms. All button objects on all forms are using FlatStyle=Flat. I have background colors on each button and tool-tips describing...
1
by: AMDRIT | last post by:
'System.Runtime.InteropServices.SEHException' occurred in system.windows.forms.dll is generated when I use "My Custom Dialog". Any ideas what I could be doing wrong? Basically, I wanted to...
2
by: Dennis C. Drumm | last post by:
This is a restatement of an earlier post that evidently wasn't clear. I am building a custom MessageBox dialog that has, among other things, a few new button options (yes to all, no to all, etc.)...
6
by: bryanhobson | last post by:
I'm fairly new to c#, and I am just trying to work out how a 'properties' dialog works. Currently in my code, I have an object represented by the class 'Dog'. The dog object has several...
4
by: ronenk | last post by:
I have this code to load an authentication form once my app is loaded. I want the authentication form to be closed if a user is authenticated successfully and to give the option to close app on his...
13
by: Mike L | last post by:
I have a child form frmDataEntry call up another child form frmDealerSearch. If the user clicks on cancel on frmDealerSearch, I want to close frmDealerSearch and put the focus on txtDealerNum on...
5
by: pswulius | last post by:
Hey everyone, for reasons I can't explain quickly, I'm developing a completely custom OK/OK_CANCEL dialog, though I think many people would benifit from this knowledge. I basically need to...
11
by: Zytan | last post by:
I have created a new form from the main form. When I close the main form with the 'x' close button, its Form.FormClosed event is run, but not the dialog's. Is this normal? It is ok /...
11
by: VK | last post by:
In the continuation of the discussion at "Making Site Opaque -- This Strategy Feasible?" and my comment at http://groups.google.com/group/comp.lang.javascript/msg/b515a4408680e8e2 I have...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.