tags:

views:

843

answers:

2

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.

+5  A: 

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

Sergio Acosta
Yeh - fair point and a confirmation dialog is exactly what happens at the moment. I'm tossing up what is more annoying, the confirmation dialog when you intentionally click cancel or the Enter Key not working. (Remember ESCAPE still works)
Stuart Helwig
But what if I accidentally hit Escape and the process stops? That would be a lot more annoying that the confirmation dialog, in my opinion. But I know that I don't have all the context about the situation and this might not be the case. Just a thought.
Sergio Acosta
People are used to confirmation dialogs. First rule of UI design is to create a design that is familiar.
workmad3
Thanks Sergio. I think you've convinced me that the status quo can remain.I still don't like confirmation dialogs though :-)
Stuart Helwig
+2  A: 

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.

Windows programmer
Yeah, add another control that does nothing and has to inintal focus.
VVS
I think this does answer my original question so to be fair I should accept it. Thanks. (Even though Sergio has talked me out of changing anything just yet ;-)
Stuart Helwig
If you accept this design, the user will still have the capability to tab to the cancel button and hit the space key to cancel. The user will not need a mouse.
Windows programmer
Yes - that was in the back of my mind. Even if you position the button way off the form, it's a bit of a hack. But you did answer the question so kudo to you.
Stuart Helwig