我使用 Visual Studio 2010 在 C# 中编码,并且有一个表单,其中有两个单选按钮和一个文本框,即:
o Radio button 1 "Yes"
o Radio button 2 "No" Textbox here
我希望加载表单时已经选择了"is"单选按钮,即:
x Radio button 1 "Yes"
o Radio button 2 "No" Textbox here (grayed out "cannot input text")
默认情况下,文本框不应接受输入。我希望这样,如果用户单击并选择 radio button 2
“No”
,文本框现在可以接受输入。
我如何实现这一目标?
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)
{
}
最佳答案
在设计模式下的 Form
上,将 TextBox
的 Enabled
设置为 False
,并设置 Checked
到第一个 RadioButton
的 True
。
将两个单选按钮附加到一个事件处理程序:
private void radioButton_CheckedChanged(object sender, EventArgs e)
{
textBox.Enabled = radioButton2.Checked;
}
关于c# - 使单选按钮默认选中并使文本框无法在 C# 中输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6068591/