Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

C# form open and close problem?

  1. Jan 2, 2012 #1
    I'm trying to make a form, form1, appear when the program is started, stay on screen for 3 seconds and then close. Form2 should then open after this.

    I tried various ways of doing it but I can't get it to work as I want it to do so. There are no bugs in the code so its purely a coding error.

    Code for form1

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

            private void Form1_Load(object sender, EventArgs e)
            {
                waitandopen();
            }

            private void waitandopen()
            {
                System.Threading.Thread.Sleep(3000);

                Form form2 = new Form2();
                form2.Show();
            }
        }
    }
    Code for form 2

    Code (Text):

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

            private void Form2_Load(object sender, EventArgs e)
            {
                closeform1();
            }

            private void closeform1()
            {
                Form form1 = new Form1();
                form1.Close();
            }
        }
    }
     
     
  2. jcsd
  3. Jan 3, 2012 #2

    CompuChip

    User Avatar
    Science Advisor
    Homework Helper

    Well, for one, in Form2 you are creating a new instance of Form1 and then closing it, instead of the instance you already have. You can have Form1 close itself, or have Form2 open it.

    But frankly, it looks like you are trying to build a splash screen - maybe that will give you a handle to search for more information.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: C# form open and close problem?
  1. C++ - File opening (Replies: 3)

  2. A problem with C (Replies: 4)

  3. C read, open (Replies: 22)

Loading...