sifa vahora sifa vahora - 1 year ago 46
C# Question

how to check if a Windows.Form is empty(without controls) but not null?

I have a function which returns an instance of Windows Form

public Form getForm(string Node)
{
Form obj = new Form();

obj = (Form)Activator.CreateInstance(Node);
return obj;
}


I am Calling this function as:

Form requestedForm = new Form();
requestedForm = getForm(system);
if ((requestedForm != null) && (requestedForm.Text!=""))
// to check if the Form is not empty.
{
openform(requestedForm);
}
else
{
MessageBox.Show("No form Found");
}


In some cases I get
requestedForm.Text=""
even if the form is not blank so how do I check this?

Answer Source
public Form getForm(string Node)
{
    Form obj = (Form)Activator.CreateInstance(Node);
    return obj;
}

Call this as:

Form requestedForm = getForm(system);
if ((requestedForm != null) && (requestedForm.Controls.Count > 0))
{//Form is not empty
    openform(requestedForm);
}
else
{
    MessageBox.Show("No form Found");
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download