如何获取 NewQuestion 按钮中的检查变量以更改表单检查变量
How can i get the check variable in the NewQuestion button to change the form check variable
如何在 NewQuestion 按钮中获取检查变量以更改表单检查
变量。
我正在考虑在此按钮更改后在另一个按钮中使用检查值。
public Form1()
{
InitializeComponent();
}
int check = 0;
private void btnNewQuestion_Click(object sender, EventArgs e)
{
int check = 1;
}
我不确定您的主要目标,我认为可能有更好的方法来完成您想要做的事情。也就是说,您可以根据需要在同一个表单中简单地引用您的表单级别变量。
public Form1()
{
InitializeComponent();
}
int check = 0; // form level variable
private void btnNewQuestion_Click(object sender, EventArgs e)
{
// int check = 1; // don't do this; this will create another 'check' variable that is only scoped within the button event
check = 1; // to set the form level check value, just reference the form level variable like so
}
private void btnSomeOtherButton_Click(object sender, EventArgs e)
{
// then reference it in the other button where you need it
if(check == 1)
{
// do some stuff
}
}
如何在 NewQuestion 按钮中获取检查变量以更改表单检查 变量。
我正在考虑在此按钮更改后在另一个按钮中使用检查值。
public Form1()
{
InitializeComponent();
}
int check = 0;
private void btnNewQuestion_Click(object sender, EventArgs e)
{
int check = 1;
}
我不确定您的主要目标,我认为可能有更好的方法来完成您想要做的事情。也就是说,您可以根据需要在同一个表单中简单地引用您的表单级别变量。
public Form1()
{
InitializeComponent();
}
int check = 0; // form level variable
private void btnNewQuestion_Click(object sender, EventArgs e)
{
// int check = 1; // don't do this; this will create another 'check' variable that is only scoped within the button event
check = 1; // to set the form level check value, just reference the form level variable like so
}
private void btnSomeOtherButton_Click(object sender, EventArgs e)
{
// then reference it in the other button where you need it
if(check == 1)
{
// do some stuff
}
}