double b = Convert.ToDouble(textBox2.Text)
string s = Convert.ToString(comboBox1.Text)
if (s == "+")
textBox3.Text = Convert.ToString(a + b)
else if(s == "坦丛-")
textBox3.Text = Convert.ToString(a - b)
else if(s == "*")
textBox3.Text = Convert.ToString(a * b)
else if(s == "/")
textBox3.Text = Convert.ToString(a / b)
代码就是这些 在窗体添加3个textbox 一个combobox一个按钮就可慎信尘以宽禅
控件如图,由左到右,由上到下,分别命名为b1,b2,b3,b4,l1,l2,button1,button2,timer1,timer2
timer1与timer2的Enabled的属性默认为false,Interval默认为1000,
后代代码如下
bool Isopen = false
int b2Times = 0
int b3Times = 0
int onebreak = 0
private void b1_Click(object sender, EventArgs e)
{
Isopen = true
if (onebreak==1)
{
timer1.Enabled = true
}
if (onebreak==2)
{
timer2.Enabled = true
}
}
private void b2_Click(object sender, EventArgs e)
{
if (onebreak==0)
{
if (Isopen == false)
{
return
}
b2Times += 1
if (b2Times >= b3Times)
{
l1.BackColor = Color.Red
l2.BackColor = Color.White
}
}
}
private void b3_Click(object sender, EventArgs e)
{
if (onebreak==0)
{
if (Isopen == false)
{
return
}
b3Times += 1
if (b3Times >= b2Times)
{
l1.BackColor = Color.White
l2.BackColor 缺颤= Color.Red
}
}
}
private void b4_Click(object sender, EventArgs e)
{
b3Times = 敏巧0
b2Times = 0
Isopen = false
l1.BackColor=Color.White
l2.BackColor = Color.White
timer1.Enabled = false
timer2.Enabled = false
}
private void button1_Click(object sender, EventArgs e)
{
if (onebreak == 1)
{
button1.Text = "第一个灯泡坏掉"
onebreak = 0
timer1.Enabled = false
button2.Enabled = true
return
}
onebreak = 1
l2.BackColor = Color.White
button1.Text = "修好它"
button2.Enabled = false
if (Isopen==false)
{
return
}
timer2.Enabled = false
timer1.Enabled = true
}
private void button2_Click(object sender, EventArgs e)
{
if (onebreak == 2)
{
button2.Text = "第二个灯泡坏掉"
onebreak = 0
timer2.Enabled = false
button1.Enabled = 桥扮键true
return
}
onebreak = 2
l1.BackColor = Color.White
button2.Text = "修好它"
button1.Enabled = false
if (Isopen == false)
{
return
}
timer2.Enabled = true
timer1.Enabled = false
}
private void timer1_Tick(object sender, EventArgs e)
{
if ( l1.BackColor != Color.Red)
{
l1.BackColor = Color.Red
return
}
if (l1.BackColor != Color.White)
{
l1.BackColor = Color.White
return
}
}
private void timer2_Tick(object sender, EventArgs e)
{
if (l2.BackColor != Color.Red)
{
l2.BackColor = Color.Red
return
}
if (l2.BackColor != Color.White)
{
l2.BackColor = Color.White
return
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)