Click here to Skip to main content
15,893,564 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C# Windows Form Application project. I have a menu form which has buttons to load other already created forms.

C#
private void cmdReporting_Click(object sender, EventArgs e)
{
    reporting frm = null;
    if ((frm = (reporting)openCheck(typeof(reporting))) == null)
    {
        frm = new reporting();
        frm.Show();
    }
    else
        frm.Select();
}



The form it is trying to load is named reporting. This code is identical to WORKING code that loads other forms. This is the only one out of 5 that won't load. It does not throw an error either.

Is there a setting I'm missing in the GUI?

Added Code for openCheck method
C#
public static Form openCheck(Type FormType)
{
    foreach (Form OpenForm in Application.OpenForms)
    {
        if (OpenForm.GetType() == FormType)
            return OpenForm;
    }

    return null;
}
Posted
Updated 25-Aug-12 9:31am
v2
Comments
Zoltán Zörgő 25-Aug-12 15:28pm    
What is "loading a form"? Show method will show a visible or hidden form, Select activates a visible form. But Show is not modal. What is the source of openCheck? How are the forms closed?
[no name] 25-Aug-12 15:30pm    
Did you debug it to find if the form is being created? If not created then what error is causing the creation to fail?
Christian Graus 25-Aug-12 20:54pm    
No - he thinks the debugger only works when your code blows up.
[no name] 25-Aug-12 21:31pm    
OMG, I see... Well CG... it's hard to help people that do not listen. I like the "working code does not trip the debugger"....
Zoltán Zörgő 25-Aug-12 16:01pm    
I would rather use the singleton pattern, like here: http://hashfactor.wordpress.com/2009/03/31/c-winforms-create-a-single-instance-form/

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900