if keyascii=vbkeyescape in VB.net

  • Thread starter Thread starter Elmo Watson
  • Start date Start date
E

Elmo Watson

in VB6 - I'd assign the Keypreview of a form to true and then dump the form
within an if then statement, like this:
if keyascii=vbkeyescape the
' unload code goes here
end if

Well - in vb.net - there's a key preview property for the form, but when you
get to the keyPress event - it's totally different, and, of course, the if
statement totally errors out -

What is in its place, in VB.Net?
 
Elmo Watson said:
in VB6 - I'd assign the Keypreview of a form to true and then dump the
form within an if then statement, like this:
if keyascii=vbkeyescape the
' unload code goes here
end if


Add a "Cancel" button to the form and assign the button to the form's
'CancelButton' property.
 
If you have a cancel button on a form, you can achieve this in a more
elegant way - select the Form and set its CancelButton property to your
CancelButton. In this case, setting KeyPreview property is not necessary.

If using a KeyPress event... you could use something like "If e.KeyChar =
Chr(27) Then Close()" ...

Andrej
 
Back
Top