我正在 Windows 窗体 (C# Visual Studio) 中制作一些东西 但我需要知道如何设置一个 int,然后在另一个事件中使用它。例如:
private void BtnYes_Click(object sender, EventArgs e)
{
int yes = 1;
int no = 0;
timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
if (yes == 1) {
//EVENT
}
}
当我这样做时,我遇到了一些错误。谁能帮我这个?或者只是告诉我如何使用不同的技术来做这样的事情?
最佳答案
您需要为此使用一个字段:
private int _yes;
private void BtnYes_Click(object sender, EventArgs e)
{
_yes = 1;
int no = 0;
timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
if (_yes == 1) {
//EVENT
}
}
关于c# - 在一个事件中设置 'int' 并在另一事件中使用它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32026591/