6 Replies - 555 Views - Last Post: 24 August 2010 - 08:34 PM Rate Topic: -----

#1 D.Mulroy  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 81
  • View blog
  • Posts: 430
  • Joined: 30-June 10

C# forms

Posted 24 August 2010 - 06:15 PM

So i've looked around a found out how to load a new form from an existing one. When I go to load the new form and close the old one, the new one will load but then both will instantly close. Whats wrong here?
  private void button1_Click(object sender, EventArgs e)
        {
            Form2 frmMain = new Form2();
            frmMain.Show();
            this.Close();
                              
        }

Is This A Good Question/Topic? 0
  • +

Replies To: C# forms

#2 Ahmedn1  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 23
  • View blog
  • Posts: 556
  • Joined: 04-August 09

Re: C# forms

Posted 24 August 2010 - 07:07 PM

View PostD.Mulroy, on 24 August 2010 - 05:15 PM, said:

So i've looked around a found out how to load a new form from an existing one. When I go to load the new form and close the old one, the new one will load but then both will instantly close. Whats wrong here?
  private void button1_Click(object sender, EventArgs e)
        {
            Form2 frmMain = new Form2();
            frmMain.Show();
            this.Close();
                              
        }


use this :

at Program.cs
instead of
Application.Run(new Form1());

use

form1 frm=new Form1();
frm.show();
application.run();

and in the button click use

form2 frmMain = new Form2();
frmMain.show();
this.dispose();
Was This Post Helpful? 1
  • +
  • -

#3 D.Mulroy  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 81
  • View blog
  • Posts: 430
  • Joined: 30-June 10

Re: C# forms

Posted 24 August 2010 - 07:26 PM

So then lets say I have another button, or a timeout event. I'd use the code inversley to close form 2 and re open form 1?
Was This Post Helpful? 0
  • +
  • -

#4 Ahmedn1  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 23
  • View blog
  • Posts: 556
  • Joined: 04-August 09

Re: C# forms

Posted 24 August 2010 - 07:38 PM

View PostD.Mulroy, on 24 August 2010 - 06:26 PM, said:

So then lets say I have another button, or a timeout event. I'd use the code inversley to close form 2 and re open form 1?


yes
that's right
Was This Post Helpful? 0
  • +
  • -

#5 D.Mulroy  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 81
  • View blog
  • Posts: 430
  • Joined: 30-June 10

Re: C# forms

Posted 24 August 2010 - 08:01 PM

I am getting the following error on this line of code: Error 1 'Uncle_Subz.Form1' does not contain a definition for 'Form1_Load' and no extension method 'Form1_Load' accepting a first argument of type 'Uncle_Subz.Form1' could be found (are you missing a using directive or an assembly reference?) C:\Users\Lisa\documents\visual studio 2010\Projects\Uncle Subz\Uncle Subz\Form1.Designer.cs 75 55 Uncle Subz

this.Load += new System.EventHandler(this.Form1_Load);

Was This Post Helpful? 0
  • +
  • -

#6 Ahmedn1  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 23
  • View blog
  • Posts: 556
  • Joined: 04-August 09

Re: C# forms

Posted 24 August 2010 - 08:11 PM

this means that you deleted the method Form1_Load()

you can double click the form to create this method
and take the name of the created method (it may be Form1_Load1 or something like that)

and replace with the name in the event handler

this.Load += new System.EventHandler(this.Form1_Load1);
Was This Post Helpful? 0
  • +
  • -

#7 D.Mulroy  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 81
  • View blog
  • Posts: 430
  • Joined: 30-June 10

Re: C# forms

Posted 24 August 2010 - 08:34 PM

Thanks :]
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1