Solved

Pressing Escape on Dialog Sends Event to Parent

Posted on 2006-06-15
3
284 Views
Last Modified: 2008-03-17
I'm trapping the Escape key in the KeyUp event of one of my forms. There is also another item that shows a windows for user input using the ShowDialog() method (I need it to block, that's why it's a dialog). The problem is that when the user presses escape on the dialog the parent window seems to get the event (and closes the form, as it should). I can't seem to find a way to detect if the escape press came from the dialog or not.. Obviously I only want the dialog to close (and return Cancel) - I don't want the opening window to see the Escape press event at all if possible but I'd like to be able to tell that it came from the dialog so I can add a conditional in there that will prevent the form close.

Help!

Thanks!
0
Comment
Question by:mitchvincent
[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
  • 2
3 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 500 total points
ID: 16911403
I think that dialog is closed by Esc KeyDown using standard dialog support - CancelButton. Instead of this handle Esc KeyUp event in the dialog and close it.
0
 

Author Comment

by:mitchvincent
ID: 16911603
That's it!

Gosh, I'm sure glad you have your thinking cap on today - mine is at the house I guess..

Thanks very much!

As a side note, when I press escape on the dialog and trap the event in the KeyUp, I do get a "beep", the one you get when trying to type somewhere you shouldn't in a windows application.

0
 
LVL 48

Expert Comment

by:AlexFM
ID: 16918065
Another solution is to close form in Esc Keydown event. In this case you don't need to change dialog.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

730 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