if keyascii=vbkeyescape in VB.net

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?
 
H

Herfried K. Wagner [MVP]

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.
 
A

Andrej Tozon

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top