简体   繁体   English

如果表单已打开,请禁用按钮和事件

[英]Disable a button and an event if a form is open

I have two forms. 我有两种形式。 The first form get info from the second form doing it this way: //First Form 第一种形式是从第二种形式获取信息的:

if (e.KeyCode == Keys.F4)
        {
            FormConsultaAdvogado fca = new FormConsultaAdvogado();
            fca.MdiParent = this.MdiParent;

            fca.Show();
        }

Then, in the second form, I choose what I need to get back to the first form with this: 然后,在第二种形式中,我选择需要返回到第一种形式的内容:

 else if (FormClienteAberto())
        {

            if (e.KeyData == Keys.Enter)
            {
                FormCliente fdil = (FormCliente)Application.OpenForms["FormCliente"];
                fdil.textBox1.Text = dataGridView1.CurrentRow.Cells[0].FormattedValue.ToString();
                fdil.textBox2.Text = dataGridView1.CurrentRow.Cells[1].FormattedValue.ToString();
                this.Close();
            }
        }

In the seconde form, I also have a funcion that verifies if the first form is open: 在第二个表单中,我还有一个函数可以验证第一个表单是否打开:

public bool FormClienteAberto()
    {
      try
        {
            Form fc = Application.OpenForms["FormCliente"];
            return fc != null;
        }
        catch (Exception)
        {
            return false;
        }

    }

So, my problems are: 所以,我的问题是:

1st- I have a button in the 2nd form that, when the first form is open, must be hide 1st-我在第二个表单中有一个按钮,当第一个表单打开时,必须隐藏

2nd- I have a RowHeaderMouseDoubleClick event that i need to disable too, if the first form is already open, too. 2-如果第一个表单也已经打开,我也需要禁用RowHeaderMouseDoubleClick事件。

Wish that you guys can help me!! 希望你们能帮助我! Regards 问候

If you just need to determine those two things when the second form is opened, something like the following in the second form's Load event should work: 如果在打开第二个窗体时只需要确定这两件事,那么第二个窗体的Load事件中的以下内容应该可以工作:

if(FormClienteAberto())
{
    thatButton.Visible = false;
    thatDataGridView.RowHeaderMouseClick -= thatRowHeaderMouseClickEventHandler;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM