Syed Ali Ahmed
Syed Ali Ahmed

Reputation: 61

How to disable child form when other child form is active in c# visual studio 2010

I want to disable only the controls of parent form onclick of a button. Like in my winform application i am loading the child form onclick of a button so i want to know that how can i just disable the controls of the form not the appearance of the parent form. Could anyone help me out please ??

Upvotes: 0

Views: 144

Answers (1)

Raging Bull
Raging Bull

Reputation: 18737

Check if the child form is in Application.OpenForms. Something like:

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;
}

For re-enabling the controls,

Parent Form

gotoChild()
{
    frmChild=new frmChild(this);
    frmChild.Show();
}

Child Form

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

Change the Modifiers property of btnGoToChild to public. Then only, it will be accessible from another form.

Upvotes: 1

Related Questions