Setting the default switch and the inability to enter a text field in C #

I am coding in C # using Visual Studio 2010, and have a form in which I have two radio buttons and a text box:

o Radio button 1 "Yes"

o Radio button 2 "No"   Textbox here

I want the form to load with the Yes 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 text field should not accept input. I want this to be the case that if the user clicks and selects radio button 2 "No", the text field can now accept input.

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)
{

}
+3
source share
3 answers

On yours Formin design mode, set the parameter Enabledto Falsefor TextBoxand Checked- Truefor the first RadioButton.

:

private void radioButton_CheckedChanged(object sender, EventArgs e)
{
    textBox.Enabled = radioButton2.Checked;
}
+2

textbox1.enabled = false onchecked , . radioobutton1.checked = true.

+1

just select the properties of your switch 1

and then select the "checked" item as true it will become obsolete. no need to code

+1
source

All Articles