c# - 我正在编写 ac# windows 窗体代码
问题描述
我正在编写 ac# windows 窗体代码以从 button1 和 button2 获取数字并将它们一起添加到文本框中,但编译器在 convert.toint32(textbox3.text) 语句上争论,它还two variable
增加three variable
了我保持不变但增加了文本框的价值,我需要一个解决方案吗?
int Three = 0;
int Two = 0;
//int one = 0;
int sum = 0;
// int sum = 0;
//int dec = 0;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// MessageBox.Show("Enter the teams` name");
}
private void button1_Click(object sender, EventArgs e)
{
//Three += 3;
//textBox3.Text = sum.ToString();
Three += 3;
sum = Convert.ToInt32(textBox3.Text) + Three;
textBox3.Text = sum.ToString();
}
private void button2_Click(object sender, EventArgs e)
{
Two += 2;
sum = Two + Convert.ToInt32(textBox3.Text) + Three;
textBox3.Text =Convert.ToInt32(textBox3.Text) + Two.ToString();
}
private void textBox3_TextChanged(object sender, EventArgs e)
{
textBox3.Text = 0.ToString();
}
`
解决方案
改变
sum = Convert.ToInt32(textBox3.Text) + Three;
至
sum = Convert.ToInt32(textBox3.Text == "" ? "0" : textBox3.Text) + 3;
另外,删除
private void textBox3_TextChanged(object sender, EventArgs e)
{
textBox3.Text = 0.ToString(); // this
}
因为这没有任何意义。
推荐阅读
- python - 弯曲的蛇与自身相撞
- android - 为 materialDatePicker 设置 180 天的日历限制
- angular - 无法从角度的 post 方法将数据分配给变量
- javascript - Socket.io 消息返回为“null”
- ios - Firebase Analytics setScreenName 已弃用
- drupal-8 - 使用 drupal 创建自定义主题
- javascript - 如何访问数组对象的元素?
- android - recyclerView 第一次滚动不流畅
- apache-zookeeper - ZooKeeper 超时 - 找不到 myid 文件。视窗服务器 2016
- firebase - Firebase 通知单击 Intent 在背景状态上显示 null - Xamarin.forms Android