deepseapanda
deepseapanda

Reputation: 3887

C# Using an array of Forms to open multiple forms at the same time

I am trying to have it so once the file is opened, multiple forms of the same form opened. So in my code below, on program execution 10 forms of test would appear. I can see it working on the ram but it doesn't want to appear, or it will appear once and after I close one form another will open :P

Any ideas on what I am doing wrong?

Thanks :)

public partial class TestFrm : Form
{
    public TestFrm()
    {
        InitializeComponent();

        loopFrm();

    }

    public void loopFrm()
    {
        int loopNumber = 10;

        Form[] TestFrm = new Form[loopNumber];

        for (int i = 1; i < loopNumber; i++)
        { 
            TestFrm[i] = new TestFrm();

            TestFrm[i].ShowDialog();
        }
    }
}

Upvotes: 1

Views: 5821

Answers (2)

Peter PAD
Peter PAD

Reputation: 2310

You should use

TestFrm[i].Show();

Instead of

TestFrm[i].ShowDialog();

When ShowDialog() is called, the code following it is not executed until after the dialog box is closed.

Upvotes: 3

Fischermaen
Fischermaen

Reputation: 12458

ShowDialog() is a modal call. It will wait until the form is closed. If you want to have all forms open use Show(). But then these form are not modal to the main form.

Upvotes: 3

Related Questions