Opening and closing Form C#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DevilInside
    New Member
    • Apr 2008
    • 5

    Opening and closing Form C#

    Hi

    In WinForms, I want to navigate from a form to another one. The problem is that he doesn't want to close the first Form when I do that.

    Code

    frmRecieve oForm = new frmRecieve ();
    oForm.ShowDialo g();

    this.Close();

    Anyone who can help? Thanks
  • todashah
    New Member
    • Feb 2008
    • 26

    #2
    If u don't want to close first form(form1) when u navigate to onther form(form2)..
    Write down following code.

    Form2 frm=new Form2();
    frm.showDialog( );

    This code work perfectly.Altho ught form2 display on screen but it is modal so u can't navigate to from1 untill u close from2.

    Bye...Take Care....Enjoy Coding

    Comment

    • Curtis Rutland
      Recognized Expert Specialist
      • Apr 2008
      • 3264

      #3
      Originally posted by DevilInside
      Hi

      In WinForms, I want to navigate from a form to another one. The problem is that he doesn't want to close the first Form when I do that.

      Code

      frmRecieve oForm = new frmRecieve ();
      oForm.ShowDialo g();

      this.Close();

      Anyone who can help? Thanks
      [code=cpp]
      frmRecieve oForm = new frmRecieve ();
      //oForm.ShowDialo g();
      //if you change this line to Show(), the forms can be switched back and forth.
      oForm.Show();
      //this.Close();
      //skip the Close() part to not close the current form.
      [/code]

      Also, if you want to be able to switch back and forth, but not be able to spawn multiple forms, set frmRecieve oForm as a public member of the parent form.
      Then, when you want to bring it up,
      [code=cpp]
      if(oForm == null || oForm.IsDispose d)
      {
      oForm = new frmRecieve();
      oForm.Show();
      }
      else
      oForm.Focus();
      [/code]

      Comment

      • DevilInside
        New Member
        • Apr 2008
        • 5

        #4
        Originally posted by insertAlias
        [code=cpp]
        frmRecieve oForm = new frmRecieve ();
        //oForm.ShowDialo g();
        //if you change this line to Show(), the forms can be switched back and forth.
        oForm.Show();
        //this.Close();
        //skip the Close() part to not close the current form.
        [/code]

        Also, if you want to be able to switch back and forth, but not be able to spawn multiple forms, set frmRecieve oForm as a public member of the parent form.
        Then, when you want to bring it up,
        [code=cpp]
        if(oForm == null || oForm.IsDispose d)
        {
        oForm = new frmRecieve();
        oForm.Show();
        }
        else
        oForm.Focus();
        [/code]
        Thanks, but I want to close the first form, but he doesn't do that.

        Comment

        • Curtis Rutland
          Recognized Expert Specialist
          • Apr 2008
          • 3264

          #5
          Originally posted by DevilInside
          Thanks, but I want to close the first form, but he doesn't do that.
          Oh, I misunderstood that, sorry. I don't know off the top of my head. Let me think about it.

          Comment

          • DevilInside
            New Member
            • Apr 2008
            • 5

            #6
            Originally posted by insertAlias
            Oh, I misunderstood that, sorry. I don't know off the top of my head. Let me think about it.
            I Finally figured it out

            FrmTest oForm = new FrmTest();
            oForm.ShowDialo g();

            this.Dispose(FA LSE);

            Thx anyway

            Comment

            Working...