【发布时间】:2012-03-06 11:10:13
【问题描述】:
我正在尝试声明 int
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动画标签的文本。到目前为止我是对的吗?当用户在选中复选框时编辑文本框中的值时,您希望发生什么?
标签: c# winforms textbox int global