4

I need to be able to create another brand new instance of a program on a button click while keeping the existing instance.

this.ShowDialog(new Form1());

The above statement causes the current form to be the owner of the new form and I need the second instance to be independent of the existing instance.

Can anyone help me with this?

4

3 に答える 3

5

You can use instead new Form1().Show();, but when your current instances exists, the other one will exit too. So, to be fully independent, it is better to use System.Diagnostics.Process.Start(string path) which starts your program exactly as if one double clicks it.

于 2012-07-04T16:31:56.630 に答える
5

To expound on Desolator's answer here is a simplistic example you can try a Form and a Button:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        Process p = new Process();
        p.StartInfo.FileName = Application.ExecutablePath;
        p.Start();
    }
}
于 2012-07-04T16:53:05.637 に答える
0
(new Form1()).Show();

(new Form1()).Show();
于 2012-07-04T16:33:51.363 に答える