Question First time using radio buttons

357mag

Well-known member
Joined
Mar 31, 2023
Messages
58
Programming Experience
3-5
I'm making a Trivia Question program. The question is "True or False: Elvis Presley died in 1977".
I've added two radio buttons to my form and when I look at the properties they both say checked is false.
But when I run my program one of the radio buttons is already checked, which is not what I want. I was hoping that they would both be unchecked, but maybe that's the way it's supposed to be?

Perhaps I would be better off having the user answer True or False in a textbox and then printing Correct or Incorrect using a label or a message box?
 
This is a Tab order "issue". When a form is displayed for the first time, the first control in the Tab order that can receive focus, will receive focus. In the case of a RadioButton, when it receives focus, is becomes checked. If you don't want that RadioButton to receive focus and become checked, you will need to do one of two things.

The first option is to change the Tab order so a different control is the first to receive focus. That may or may not be practical, depending on your form structure. You can change the TabIndex property of each control in the Properties window, but you ought to use the View menu to display all Tab indexes and then click the controls in the order you want.

If you can't modify the Tab order, you can handle the Load event of the form and manipulate the state there. You can focus a different control or no control at all, then uncheck that RadioButton. That might look like this:
C#:
// Focus no control. Assign a different control if desired.
ActiveControl = null;

// Uncheck the RadioButton.
RadioButton1.Checked = false;
 
It appears I solved the problem. Now when I run my program, both radio buttons are unchecked and I can choose either True or False.
 
Maybe not so fast. I'm having the same issue with another radio button program. I will look at the code you posted and see how far I can get.
 
I highly recommend fixing the tab order. The Windows UI guidelines state that when you open a new window, the focus should be on the default button of the window (e.g. either the OK or Cancel button). If you follow that guideline, then you would never have the focus on one of your radio buttons.
 
If you want a fairly simple, no-code, but hacky way of solving this, create another radiobutton that is first in the tab order, and then hide it off screen somewhere

Don't forget that you can do View menu >> Tab Order, and then you can use your mouse, clicking everything in the order you want the tab order to be, to set the tab order
 
Back
Top Bottom