views:

274

answers:

3

In a simple Guess-The-Number game I'm making, the user inputs a couple of numbers and hits a button. A second panel becomes enabled and the original one is disabled. The user now enters a number and hits another button, multiple times. Since the two panels will never be enabled at the same time, I'd like for both buttons to be "default", i.e., they will be pushed if Enter is pressed. Is this possible? Apparently, I can only set one of these per window.

A: 

Nope, no way to accomplish that that I know of. You'll have to switch the default button when one button is pressed to the next button.

jasonh
+1  A: 

A window in Windows by definition has only one default button. This is a functionality intended for dialog windows where you would never disable the default button.

What you can do instead is to switch the default button when you disable one panel.

Another option would be to throw out default buttons altogether and use KeyPreview on the form and handle the enter key yourself, sending it to the appropriate button that is currently active.

Joey
A: 

You can only have one default button per window. However, this can be changed at runtime, so when you activate a specific panel, you can make it's button the default one at that point.

Reed Copsey