how to close one form and show another form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • agarwalsunitadhn
    New Member
    • Jan 2008
    • 82

    how to close one form and show another form

    hello
    i am working in C#.net. I want to know how to close one form and show another one. I had done the following code
    Code:
                    this.Hide();
                    MainForm frm = new MainForm();
                    frm.Show();
                    frm.Focus();
                    frm.Activate();
    but when i close the last form activated then still it shows that the application is running. how can i completly close the first form
  • spacemanafrica
    New Member
    • Mar 2008
    • 6

    #2
    One application can have multiple forms and it looks like that's what you're doing. Is that true? If so, the same executable will show up in the Task Manager for both forms.

    -S.

    Comment

    • dip_developer
      Recognized Expert Contributor
      • Aug 2006
      • 648

      #3
      Originally posted by agarwalsunitadh n
      hello
      i am working in C#.net. I want to know how to close one form and show another one. I had done the following code
      Code:
      this.Hide();
      MainForm frm = new MainForm();
      frm.Show();
      frm.Focus();
      frm.Activate();
      but when i close the last form activated then still it shows that the application is running. how can i completly close the first form
      suppose you want to close Form1 and show Form2 ...then in the Form_Closing event of Form1 write the following code...

      [CODE=css]
      Form2 frm2;
      private void Form1_Closing(o bject sender, System.EventArg s e)
      {
      frm2 = new Form2();
      frm2.Show();
      }
      [/CODE]

      Comment

      • agarwalsunitadhn
        New Member
        • Jan 2008
        • 82

        #4
        Originally posted by dip_developer
        suppose you want to close Form1 and show Form2 ...then in the Form_Closing event of Form1 write the following code...

        [CODE=css]
        Form2 frm2;
        private void Form1_Closing(o bject sender, System.EventArg s e)
        {
        frm2 = new Form2();
        frm2.Show();
        }
        [/CODE]
        I had done the code provided by you bt it has the same problem as i previously written. what I done is that i call the Form1_Closing event from a button's click event. It shows both the form and application doesnt stop running. But when i close the newly created form i.e. Form2 then it will wait for the first one to close for termination of Application and when i click the first one form i.e. Form1 then the whole application terminate

        Comment

        Working...