如何实现 RadioButton 被选中 textBox不可用?

解决方案 »

  1.   

    先将所有的radioButton控件的CheckedChanged事件都赋值为radioButton1_CheckedChanged
    private void radioButton1_CheckedChanged(object sender, EventArgs e)
    {
        // 假设radioButton1对应textBox1、radioButton2对应textBox2、radioButtonN对应textBoxN    // 恢复原始状态
        for (int i = 1; i <= 3; i++)
        {
            Control[] controls = Controls.Find(string.Format("textBox{0}", i), true);
            if (controls.Length > 0) controls[0].Enabled = true;
        }    Control[] textBoxs = Controls.Find(string.Format("textBox{0}",
            ((Control)sender).Name.Remove(0, "radioButton".Length)), true);
        if (textBoxs.Length > 0) textBoxs[0].Enabled = false;
    }
      

  2.   

    在CheckedChanged事件中,判断if(radioButton1.Checked == true)则把与之对应的textBox.Ealbe = false;或者readonly = true;
      

  3.   

    if(RaddioButton.Checkde)
          TextButton.Enable=false;