Phillip Morton
Phillip Morton

Reputation: 244

Starting the same form more than once

I currently have a project, with a form containing a Panel, called Panel1.

There are no classes, or anything in the form as all the code is held in my control library.

I can start up a single instance of the form with one of my 4 User Controls, however I am looking to have each controls start up in different windows, using the same Form, with the panel.

I have played with the program.cs to allow this, but each form needs to close before opening the next.

Has anyone got any ideas?

THis is not a duplicate of the question cited. As I am attempting to open 1 form, but with different instances of a usercontrol, co currently.

Upvotes: 0

Views: 1026

Answers (2)

sanjay bhansali
sanjay bhansali

Reputation: 327

try this i run two form simultaneously

 static class Program
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        var thread = new Thread(ThreadStart);
        // allow UI with ApartmentState.STA though [STAThread] above should give that to you
        thread.TrySetApartmentState(ApartmentState.STA);
        thread.Start(); 
        Application.Run(new Form1());

    }
    private static void ThreadStart()
    {
        Application.Run(new Form2()); 
    }

}

Upvotes: 1

Sergey Berezovskiy
Sergey Berezovskiy

Reputation: 236228

Use form.Show() instead of form.ShowDialog() to open form more than once without need to close it.

Upvotes: 1

Related Questions