Making a radio button selected by default and making a textbox unable to take input in C#
I am coding in C# using Visual Studio 2010 and have a form whereby I have two radio buttons and a textbox, that is:
o Radio button 1 "Yes"
o Radio button 2 "No" Textbox here
I want the form to load with the "Yes" radio button already selected, that is:
x Radio button 1 "Yes"
o Radio button 2 "No" Textbox here (grayed out "cannot input text")
By default, the textbox should not accept input. I want it such that if a user clicks and selects radio button 2
"No"
, the text box is now able to accept inpu开发者_如何学运维t.
How do I achieve this?
private void rb_taxable_yes_CheckedChanged(object sender, EventArgs e)
{
}
private void rb_taxable_no_CheckedChanged(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
On your Form
in design mode set Enabled
to False
for the TextBox
, and Checked
to True
for the first RadioButton
.
Attach both radiobuttons to one event handler:
private void radioButton_CheckedChanged(object sender, EventArgs e)
{
textBox.Enabled = radioButton2.Checked;
}
Start out with textbox1.enabled = false, and use the onchecked event for the second radio button to change that. also set the first radio button to have radiobutton1.checked = true.
just choose the properties of your radio button 1
and then select the "checked" item as true it will set as defult. no need to code
精彩评论