open forms from its name string

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fradique
    New Member
    • Dec 2006
    • 2

    open forms from its name string

    It was hard to figure out this, i searched in the internet but i didnt find a solution, i found a solution if you have something better or any comments plese tell me.

    Code:
    string formName="frmTest";
    Type tForm = Type.GetType(Application.CompanyName + "." + formName);
    if (tForm != null)
                    {
                        Form f = (Form)Activator.CreateInstance(tForm);
                                f.Show();
    }
  • codesid
    New Member
    • Dec 2006
    • 6

    #2
    As far as I know, this is pretty much it.

    Only one thing from System.Activato r that you may should know... when using it to instantiate classes which require constructors with parameters, you may use one of the other overloads of the same method that you have, but only for public classes. I could not get it to work with internal classes. If you have a situation like that, you may consider encapsulating the class, or turning it public, if does not affect the rest of your project/solution.

    Cheers.

    Comment

    Working...