1

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();
        }
    }
}

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

7 Comments

because the forms open so fast am I able to slow them down at all?
You can do that with a Thread.Sleep(1000) between two form.Show()'s. This will wait 1000 msec.
Hmm visual studio won't allow me to use thread...Also the way I have it at the moment with the method called on the form, each new form also has the loop method, so instead of 10 I end up with a larger amount, am I able to declare a parent form and only have it called on that? I was thinking of making 2 forms of the same content and having the first form call the others, is there a simpler way in code ? Thanks :)
What you have done in your sample above is a never ending loop. In the constructor of the form you call the method 'loopForm. This opens 10 new instances of the same form. In every of those 10 new instances you call loopForm` in the constructor. So at the end of the first "round" you'll have 100 forms. Second "round" gives you 1000 forms, ... and ... it will never end! You'll have to rethink the program logic again.
ended up using another form, so the parent form calls the children :P The timer is working now, i used System.Threading.Thread.Sleep(1000);
|
3

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.