你如何让一个按钮一键完成多个事件

本文关键字:一键 按钮 事件 一个 | 更新日期: 2023-09-27 18:35:16

所以我试图在我的代码中显示一些标志,这些标志只是文本框或标签。如何让他们同时显示多个标志,而不必单击我的按钮 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();

你如何让一个按钮一键完成多个事件

尝试移动:

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

紧接着

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