无法将类型“string”隐式转换为“int”。拜求!!!!谢谢!!!
我用C#做个很简单的倒计时,在textBox1中输入数据m,然后利用timer1控件,就m--倒计时啊。运行报错:无法将类型“string”隐式转换为“int”。所有代码都在下面了。大哥大姐教教我吧。谢谢。
int m;
private void textBox1_TextChanged(object sender, EventArgs e)
{
if(this.textBox1.Text != "")
{
m = this.textBox1.Text;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
m--;
this.label2.Text = m.ToString()+"秒";
label2.Refresh();
}
private void button1_Click(object sender, EventArgs e)
{
this .timer1.Enabled =true;
}
------解决方案--------------------int.Parse
------解决方案--------------------m = int.Parse(this.textBox1.Text);
------解决方案--------------------
C# code
private void textBox1_TextChanged(object sender, EventArgs e)
{
if(this.textBox1.Text != "")
{
[b]m = Convert.ToInt32(this.textBox1.Text);[/b]
}
}
private void timer1_Tick(object sender, EventArgs e)
{
m--;
this.label2.Text = m.ToString()+"秒";
label2.Refresh();
}
private void button1_Click(object sender, EventArgs e)
{
this .timer1.Enabled =true;
}