break windows execution on key press event

A

andrew

I am trying to allow a windows form to accept an escape
character to cancel the current operation (drawing a line
on panel control contained within the form).
I thought that the forms KeyPress or KeyDown event would
suffice, but I have tried them and they don't seem to work.

My form has a treeview docked to the LHS side, with a
splitter control and then a panel filling the RHS.

I have tried various combinations and find that the key
pressed event doesn't seem to fire when my form has a
treeview control on it (i.e I tried various combinations
of blank form, form with one panel det to fill, form with
two panels docked and splitters etc and I was able to
display a message informing me of the key pressed event.

Is this a glitch and does anyone have ideas on how to
overcome?

Thanking a helpful soul in advance.

Andrew
 
H

Herfried K. Wagner [MVP]

* "andrew said:
I am trying to allow a windows form to accept an escape
character to cancel the current operation (drawing a line
on panel control contained within the form).
I thought that the forms KeyPress or KeyDown event would
suffice, but I have tried them and they don't seem to work.

My form has a treeview docked to the LHS side, with a
splitter control and then a panel filling the RHS.

I have tried various combinations and find that the key
pressed event doesn't seem to fire when my form has a
treeview control on it (i.e I tried various combinations
of blank form, form with one panel det to fill, form with
two panels docked and splitters etc and I was able to
display a message informing me of the key pressed event.

You can add a button and define it as the form's 'CancelButton'. Or
you can set the form's 'KeyPreview' property to 'True' and wait for Esc
in the form's 'KeyDown' event handler.
 

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