Question

I have a form with a progress bar and a cancel button which is displayed as a process runs. The buttons "Cancel" property is set to true so pressing escape, cancels the process.

But, as the button is the only control on the form capable of taking the focus, should the user inadvertently press enter (or space bar) while the process is running it will be cancelled.

I have prevented the Space Bar from working by setting KeyPreview to true (on the form) then setting KeyAscii to 0 but this approach deson't seem to work for the enter key as the button click event fires first.

I've tried setting the button's TabStop property to "false" - no change.

Was it helpful?

Solution

Add a default button with size 1x1, no caption, no border, etc. Make a handler for it that does nothing. The Escape key will still do a cancel as it does now.

OTHER TIPS

In my opinion, the Enter key should activate the cancel button. Or are you requiring the user to reach out for the mouse? why?

I suggest adding just a confirmation dialog after the user cancels the operation, so if anyone accidentally presses the Enter key have the chance to resume saying 'no, I don't want to cancel'.

But as a user I would be annoyed if the Cancel button has the focus and I can't activate it pressing the Enter key on my keyboard.

My 2 cents

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top