如何只用一次点击即可使1个按钮执行多个事件?

时间:2013-10-14 03:01:16

标签: c# button textbox

所以我试图在我的代码中显示一些标志,这些标志只是文本框或标签。如何让他们同时显示多个标志而无需单击我的按钮2次?

下面的代码是8位寄存器的设置,8位输入A和8位输入B.我想输出8位,并且想要显示进位标志,如果另外使用进位如果有溢出,则溢出。我遇到的问题是同时显示溢出和进位标志,而不必单击按钮2次。

textBox29.Visible = false;
textBox30.Visible = false;
string registera, registerb;
registera = textBox1.Text + textBox2.Text + textBox3.Text + textBox4.Text + textBox5.Text + textBox6.Text + textBox7.Text + textBox8.Text;
registerb = textBox26.Text + textBox25.Text + textBox24.Text + textBox23.Text + textBox22.Text + textBox21.Text + textBox20.Text + textBox19.Text;
int output = Convert.ToInt32(registera, 2);
int output2 = Convert.ToInt32(registerb, 2);
output = output + output2;
string binary = Convert.ToString(output, 2);

for (int i = 7; i >=1; i--)
{
    if (registera[i] == '1' && registerb[i] == '1')
    {

        Carryflag.Visible = true;
     }
}   


if (output == 0)
{
    textBox28.Visible = true;
}
else textBox28.Visible = false; 

if (output > 255)
{
    Carryflag.Visible = true;
}

if (textBox18.Text == "1")
{
    OverflowFlag.Visible = true;
}



binary = binary.PadLeft(9, '0');

textBox18.Text = binary[0].ToString();
textBox16.Text = binary[1].ToString();
textBox15.Text = binary[2].ToString();
textBox14.Text = binary[3].ToString();
textBox13.Text = binary[4].ToString();
textBox12.Text = binary[5].ToString();
textBox11.Text = binary[6].ToString();
textBox10.Text = binary[7].ToString();
textBox9.Text = binary[8].ToString();

1 个答案:

答案 0 :(得分:0)

尝试移动:

 if (textBox18.Text == "1")
 {
    OverflowFlag.Visible = true;
 }

紧接在

之后
textBox18.Text = binary[0].ToString();