嗨,我刚刚为文本框的 keydown 事件编写了一个方法。这里的问题是:我需要一个变量是“静态的”,也就是说,变量的变化可以保留给方法的下一次运行。我尝试使用静态,但似乎只有静态方法可以允许这样的声明。
请问我能做些什么来解决这个问题?非常感谢!
private void textBox1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if (e.KeyCode != Keys.Enter) return;
if (comboBox1.SelectedIndex == 0)
{
if (textBox1.Text == "00000000")
{
typeselected = true;
type = 0;
}
else if (textBox1.Text == "00000001")
{
typeselected = true;
type = 1;
}
else if (textBox1.Text == "00000002")
{
typeselected = true;
type = 2;
}
else if (textBox1.Text == "00000003")
{
typeselected = true;
type = 3;
}
else if (textBox1.Text == "00000004")
{
typeselected = true;
type = 4;
}
else if (textBox1.Text == "00000005")
{
typeselected = true;
type = 5;
}
else if (textBox1.Text == "00000006")
{
typeselected = true;
type = 6;
}
else if (typeselected) { typeselected = excel0(textBox1.Text, type); }
}