我想申报INT声明全局整数在winform
private int i = 15 - textBox1.Text.Length;
本代码
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked == true)
{
i = 15 - textBox1.Text.Length;
timer1.Enabled = true;
timer1.Start();
}
else
{
timer1.Enabled = false;
}
}
private int i = 15 - textBox1.Text.Length; //this wont work but i need it to
private int y = 15 - textBox1.Text.Length; //this wont work either but i also need it to
private void timer1_Tick(object sender, EventArgs e)
{
if (i <= 11)
{
i++;
string ping = new string(' ', i) + textBox1.Text;
label1.Text = ping;
if (i == 10)
{
y = 11;
}
}
else if (y > 0)
{
y--;
string pong = new string(' ', y) + textBox1.Text;
label1.Text = pong;
if (y == 0)
{
i = 0;
}
}
}
一个全球性的整数,但我得到的错误
一个字段初始不能引用非静态字段,方法或属性'text_test.Form1.textBox1'
有帮助吗?
从我可以告诉你有一个'TextBox',一个'CheckBox'和'Label'窗体上,当你选中复选框,你需要一个'Timer'来为标签的文本设置动画。我到目前为止是否正确?当用户在复选框被选中时编辑文本框中的值时,您希望发生什么? – 2012-02-16 00:30:31