Click here to Skip to main content
12,396,047 members (67,272 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# Windows Forms
C# Windows Form Application project. I have a menu form which has buttons to load other already created forms.

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
public static Form openCheck(Type FormType)
{
    foreach (Form OpenForm in Application.OpenForms)
    {
        if (OpenForm.GetType() == FormType)
            return OpenForm;
    }
 
    return null;
}
Posted 25-Aug-12 9:23am
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?
Wes Aday 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.
Wes Aday 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/
joeswindell 25-Aug-12 21:51pm
   
Thank you Zoltan, that would be a much better solution.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 25 Aug 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100