C# 如果窗体处于打开状态,则禁用按钮和事件
我有两张表格。第一个表单通过以下方式从第二个表单获取信息: //第一种形式C# 如果窗体处于打开状态,则禁用按钮和事件,c#,winforms,visual-studio-2012,C#,Winforms,Visual Studio 2012,我有两张表格。第一个表单通过以下方式从第二个表单获取信息: //第一种形式 if (e.KeyCode == Keys.F4) { FormConsultaAdvogado fca = new FormConsultaAdvogado(); fca.MdiParent = this.MdiParent; fca.Show(); } 然后,在第二种形式中,我选择我需要的东西,通过以下方式返回
if (e.KeyCode == Keys.F4)
{
FormConsultaAdvogado fca = new FormConsultaAdvogado();
fca.MdiParent = this.MdiParent;
fca.Show();
}
然后,在第二种形式中,我选择我需要的东西,通过以下方式返回到第一种形式:
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();
}
}
在第二个表单中,我还有一个验证第一个表单是否打开的函数:
public bool FormClienteAberto()
{
try
{
Form fc = Application.OpenForms["FormCliente"];
return fc != null;
}
catch (Exception)
{
return false;
}
}
因此,我的问题是:
第一个-我在第二个表单中有一个按钮,当第一个表单打开时,必须隐藏该按钮
第二个-如果第一个表单也已打开,我还需要禁用RowHeaderMouseDoubleClick事件
希望你们能帮助我!!
关于如果您只需要在打开第二个表单时确定这两件事,那么第二个表单的加载事件中的类似内容应该可以工作:
if(FormClienteAberto())
{
thatButton.Visible = false;
thatDataGridView.RowHeaderMouseClick -= thatRowHeaderMouseClickEventHandler;
}
我已经尝试过这种方法,但是按钮仍然可见,事件也仍然打开:\n您确定FormClienteAbberto函数返回正确的值吗?是的,因为我在执行de if时将所有正确的值都转换为正确的形式:|好的,我刚刚解决了这个问题。我用ifFormClienteAberto重新定位到Form_加载,它现在正在工作!谢谢你,乔治