Function to execute forms from other solutions C #

If someday you encounter the problem of wanting to create a system with many modules and choose to separate each module in a different project, you will surely need to execute the forms and visibly it seems that it is just a system. To achieve this, I bring you the following function, hoping it will be useful for you.

public Form loadForm(string NameSpace, 
                             string path, 
                             string nameForm)
{
   Assembly wSTproject = Assembly.LoadFrom(path);
   nameForm = Namespace + "." + nameForm;
   Type wTY = wSTproject.GetType(nameForm);
   return (Form)Activator.CreateInstance(wTY);
}

Mode of use

loadForm("QualityInfoSolutions.Presentation",
                 @"C:\Development\ProjectTest.exe", 
                 "frmTest").ShowDialog();

Note: the route extension can be .exe or .dll depending on how you created the solution

regards

También te podría gustar...