c# - 如何在文本框得分为 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;
}
}
这将从另一个面板启用“平均”按钮。
解决方案
但是你为什么要检查文本而不是实际数据呢?这是该问题的解决方案。
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
将上面的代码片段实施到您的代码中,您就可以开始了。
推荐阅读
- javascript - 如何使用 simple-git (NODEJS) 提交和推送?
- javascript - Angular 订阅无法按我的预期工作
- php - 使用 Composer 安装包
- node.js - 测试快速 HTTPS 服务器时的“app.address 不是函数”
- django-rest-framework - 如何在 django restframework 中获取项目名称而不是项目 ID(外键案例)
- dart - 使用带有 add() 方法的 dart 将元素添加到 2d 列表
- flutter - Flutter:我可以使用 Provider.of
在普通类组件中? - kotlin - 如何在 Kotlin 中制作集合的深拷贝?
- sql-server - SSAS 标准版表格模型过程 - 内存不足错误
- node.js - 如何使用正确的导入语法来替换“require”?