Click here to Skip to main content
15,893,668 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am new to C#
I have a two forms name form1 and form2
My main form is Form1 so i want to do this if this program runs first time hide the Form1 and Show Form2 but two forms are keep showing

time default value is 1 it's increment by 1 in Formclose event
I use this code to check and show Form2
What is the wrong
Thank in advance


C#
private void Form1_Load(object sender, EventArgs e)
        {

           if (my_app.Properties.Settings.Default.time == 1)
           {
               this.Hide();
               Form2 sf = new Form2();
               sf.Show();
           }
        }
Posted

1 solution

You don't show where you increment the .time setting, but if you don't .Save() it, then it won't be available for the next startup of the application. You also don't mention where you decrement it so maybe .time is always > 1.

This isn't the best way to do this, you should examine the running processes and if you already have one running, then show a different form. Search google for Single Instance Applications C#, same concept except you are not quitting, you are showing a different form.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900