Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在其他子窗体在c#visual studio 2010中处于活动状态时禁用子窗体_C#_Visual Studio 2010 - Fatal编程技术网

如何在其他子窗体在c#visual studio 2010中处于活动状态时禁用子窗体

如何在其他子窗体在c#visual studio 2010中处于活动状态时禁用子窗体,c#,visual-studio-2010,C#,Visual Studio 2010,我只想在单击按钮时禁用父窗体的控件。就像在winform应用程序中一样,我只需点击一个按钮即可加载子窗体,因此我想知道如何禁用窗体的控件而不是父窗体的外观。谁能帮我一下吗 检查子窗体是否在应用程序.OpenForms中。比如: bool IsOpen=false; FormCollection fc = Application.OpenForms; foreach (Form frm in fc) { if(frm.Name=="YourFormName") IsOpen

我只想在单击按钮时禁用父窗体的控件。就像在winform应用程序中一样,我只需点击一个按钮即可加载子窗体,因此我想知道如何禁用窗体的控件而不是父窗体的外观。谁能帮我一下吗

检查子窗体是否在
应用程序.OpenForms
中。比如:

bool IsOpen=false;
FormCollection fc = Application.OpenForms;
foreach (Form frm in fc)
{
    if(frm.Name=="YourFormName")
        IsOpen=true;
}
if(IsOpen)
{
    //Child form is open
    btnGoToChild.Enabled=false;
}
else
{
    //Not open
    btnGoToChild.Enable=true;
}
为了重新启用控制

父表单

gotoChild()
{
    frmChild=new frmChild(this);
    frmChild.Show();
}
frmParent ObjParent=null;
frmChild(frmParent obj)   //Constructor
{
    this.ObjParent=obj;
}
CloseForm()  //invoke this function in Form_Close
{
    if(ObjParent!=null)
        ObjParent.btnGoToChild.Enabled=true;
}
子表单

gotoChild()
{
    frmChild=new frmChild(this);
    frmChild.Show();
}
frmParent ObjParent=null;
frmChild(frmParent obj)   //Constructor
{
    this.ObjParent=obj;
}
CloseForm()  //invoke this function in Form_Close
{
    if(ObjParent!=null)
        ObjParent.btnGoToChild.Enabled=true;
}

将btnGoToChild的
修饰符
属性更改为
公共
。只有这样,它才能从另一个表单访问。

你能告诉我在哪里写这段代码吗?我是c#的初学者,请指导我。我有一个代码New form=New New();form.Show();左=190;表1.Top=140;在按钮上您想禁用该按钮,对吗?因此,您必须在父窗体的
窗体\u Load
中编写此代码。如果您需要进一步的帮助,我很乐意提供帮助。我只想禁用控件,而不想禁用父窗体的外观。我已编辑了我的答案。现在试试看。转到调试模式并逐行检查。