如果其他radiobutton中有特定文本,如何隐藏radiobutton?

时间:2018-05-15 10:11:02

标签: c# if-statement radio-button

我正在家里做一个基本上是多项选择测验的项目,单选按钮的答案附带一个字符串方法(问题来自pictureBox),一旦你回答了最后一个问题我就注意到了并且没有更多问题要回答,程序崩溃了。

我试图通过添加1张更像“QUIZ OVER”的图片并隐藏radioButtons来防止这种情况,但我不知道如何在特定情况下隐藏radioButtons。

我尝试过这种类型的代码,但它不起作用:

if (radioButton1.Text("Answer");
{
radioButton1.Hide;
radioButton2.Hide;
radioButton3.Hide;
}

1 个答案:

答案 0 :(得分:0)

您的代码存在以下问题:

1-我们没有为RadioButton提供Text()方法,既没有C#WinApp也没有C#WebApp。

2-因此,if条件将更改为if (radioButton1.Text == "Answer")

3-因此,在WinForm中,您可以使用Visable

radioButton1.Visable = false属性

4-最后,代码应该改为:

if (radioButton1.Text == "Answer")
{
    radioButton1.Visable = false;
    radioButton2.Visable = false;
    radioButton3.Visable = false;
}

但是如果你想检查是否radioButton1检查了条件是否为if (radioButton1.Checked)