Passing through forms?

This is a discussion on Passing through forms? within the C# Programming forums, part of the General Programming Boards category; i can open another form in the main form but i want when the 2nd form is opened the main ...

  1. #1
    Registered User Aga^^'s Avatar
    Join Date
    Aug 2008
    Posts
    71

    Passing through forms?

    i can open another form in the main form but i want when the 2nd form is opened the main form will be closed

    Code:
    if (OgrenciGiris == null)    //main form is frmPersonelGiris 2nd form is frmOgrenciGiris
                       {
                           PersonelGiris = new frmPersonelGiris();
                           PersonelGiris.Close();
                           OgrenciGiris = new frmOgrenciGiris();
                           OgrenciGiris.Show();
                       }
    how can i do that?

  2. #2
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,059
    Quote Originally Posted by Aga^^ View Post
    i can open another form in the main form but i want when the 2nd form is opened the main form will be closed

    Code:
    if (OgrenciGiris == null)    //main form is frmPersonelGiris 2nd form is frmOgrenciGiris
                       {
                           PersonelGiris = new frmPersonelGiris();
                           PersonelGiris.Close();
                           OgrenciGiris = new frmOgrenciGiris();
                           OgrenciGiris.Show();
                       }
    how can i do that?
    You can't. You'll have to hide the main form as follows:

    Code:
      PersonelGiris.Hide();
    as opposed to closing it.

  3. #3
    Registered User Aga^^'s Avatar
    Join Date
    Aug 2008
    Posts
    71
    i tried it but i did not work
    there is something suspecting me
    the

    Code:
     public partial class frmPersonelGiris : Form // the main form is frmPersonelGiris
        {
            public frmOgrenciGiris OgrenciGiris;
            public frmPersonelGiris PersonelGiris;
            
            private void button1_Click(object sender, EventArgs e)
            {
                 if (OgrenciGiris == null)
                       {
                           PersonelGiris = new frmPersonelGiris();
                           PersonelGiris.Hide();
                           OgrenciGiris = new frmOgrenciGiris();
                           OgrenciGiris.MainForm = this;
                           OgrenciGiris.Show();
                       }
             }
       }
    when i did not write
    Code:
    public frmPersonelGiris PersonelGiris;
    in the top of the form it did not work
    how can i do it?

  4. #4
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    If you have two forms you want to show one after another, call both of them from your main method. Don't have one call the other, if you close the first, the second will be gone, too.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  5. #5
    Registered User Aga^^'s Avatar
    Join Date
    Aug 2008
    Posts
    71
    how? what did you mean in main method ? i want after clicked on a button the first form will closed and the second form will open

  6. #6
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    PersonelGiris = new frmPersonelGiris();
    PersonelGiris.Hide();
    Don't you realize what you're doing here? Read through these and try to understand why the main form (which has already been created) does not hide.

    Also, note that if you hide the main form you have to manually close it or manually exit the program or it will still be running in the background, not visible to you.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  7. #7
    Registered User Aga^^'s Avatar
    Join Date
    Aug 2008
    Posts
    71
    ok i fixed it you are right magos
    thanks magos and nvoigt

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newb Question on Passing Objects as Parameters
    By Mariano L Gappa in forum C++ Programming
    Replies: 12
    Last Post: 11-29-2006, 01:08 PM
  2. passing a structure pointer by value
    By Bleech in forum C Programming
    Replies: 6
    Last Post: 07-11-2006, 06:58 PM
  3. Need help passing a variable between forms
    By GUIPenguin in forum C# Programming
    Replies: 8
    Last Post: 07-10-2006, 04:13 AM
  4. Passing by reference not always the best
    By franziss in forum C++ Programming
    Replies: 3
    Last Post: 10-26-2005, 08:08 PM
  5. Compiler "Warnings"
    By Jeremy G in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 04-24-2005, 02:09 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21