我的问题是我的程序在 button21 的函数之间循环时遇到了麻烦,这取决于 if 语句的编写顺序,if 函数可以工作,但另一个不会。在下面的代码中,我将其设置为 button2,但我希望按钮 1 和按钮 2 都可以与 button21 一起使用,如果它们被选中的话。但是功能设置 qw==1 是在这个程序中工作的不是 qw==2 那么我的程序代码有什么问题?代码显示:
namespace Matematisk_indlæring
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Random RND = new Random(Guid.NewGuid().GetHashCode());
Random RND2 = new Random(Guid.NewGuid().GetHashCode());
private void quitToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}
private void button1_Click(object sender, EventArgs e)
{
button1.Hide();
button2.Hide();
button3.Hide();
button4.Hide();
button5.Hide();
label1.Show();
textBox1.Show();
button21.Show();
double qw = 1;
textBox2.Text = qw.ToString();
string q = "1+1";
label1.Text = q;
int qq = 1 + 1;
textBox3.Text = qq.ToString();
}
private void button21_Click(object sender, EventArgs e)
{
double qqq = Convert.ToDouble(textBox1.Text);
double qq = Convert.ToDouble(textBox3.Text);
int qw = Convert.ToInt32(textBox2.Text);
if (qw == 1)
{
if (qq == qqq)
{
MessageBox.Show("succes");
int qws1;
int qws;
qws1 = RND2.Next(51, 100);
qws = RND.Next(0, 50);
qq = qws1 + qws;
textBox3.Text = qq.ToString();
string tese = qws.ToString();
string tese2 = qws1.ToString();
label1.Text = tese2 + "+" + tese;
}
if (qw == 2)
{
if (qq == qqq)
{
MessageBox.Show("succes");
int qws1;
int qws;
qws1 = RND2.Next(51, 100);
qws = RND.Next(0, 50);
qq = qws1 - qws;
textBox3.Text = qq.ToString();
string tese = qws.ToString();
string tese2 = qws1.ToString();
label1.Text = tese2 + "-" + tese;
}
}
}
}
private void button2_Click(object sender, EventArgs e)
{
button1.Hide();
button2.Hide();
button3.Hide();
button4.Hide();
button5.Hide();
label1.Show();
textBox1.Show();
button21.Show();
double qw = 2;
textBox2.Text = qw.ToString();
string q = "1-1";
label1.Text = q;
int qq = 1 - 1;
textBox3.Text = qq.ToString();
}
}
}