首页 > 解决方案 > 如何在文本框得分为 5 后启用按钮?

问题描述

我正在做我的学校项目,但我无法调试我的代码。当文本框得分达到 5 时,我无法从另一个面板启用平均按钮。

if单击其他面板中的所有正确答案时,我已经尝试过循环。

private void Quizportion_Load(object sender, EventArgs e)
{
    if(txtScoreTab = "5")
        //(rbtnA1.Checked && rbtnC2.Checked && rbtnEasyA3.Checked && rbtnEasyA4.Checked && rbtnEasyD5.Checked){
        btnAverage.Enabled = true;
    }
}

这将从另一个面板启用“平均”按钮。

标签: c#

解决方案


但是你为什么要检查文本而不是实际数据呢?这是该问题的解决方案。

private int counter_ = 0;
public int counter 
{
    get { return counter_; }
    set {
         //You don't have to worry about the variable 'value'. 
         if(value == 5) btnAverage.Enabled = true; // it checks if the value is 5
         txtScoreTab.Text = value.ToString(); //when the value of counter is updated, txtScoreTab.Text changes correspondingly.
         counter_ = value; // the value of counter updates here. 
    }
}

解释如下:当计数器被更新时,它会检查它的值是否达到5,如果是,则按钮将被启用。您应该做的是在每次更新时增加计数器。

例子

counter = 4; 
counter++; // At this point, the button will be enabled The text will be updated as well. You can also write counter += 1; as well

将上面的代码片段实施到您的代码中,您就可以开始了。


推荐阅读