how to open 2nd form from 1st and close the 1st one simultaneously

Discussion in 'C#' started by dreskei, Oct 22, 2010.

  1. dreskei

    dreskei New Member

    Joined:
    Oct 22, 2010
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    student
    Location:
    delhi
    i have two window application forms form1-registeruser.cs
    form2-details.cs
    on clicking REGISTER button on form1,form2 is opened
    but form1 is still there .....i am not getting how to close form1 with form2 still open
    my code was as follows
    private void REGISTERbtn_Click(object sender, EventArgs e)
    {
    details obj=new details();
    obj.show();
    close();
    }
    but this code closes both the forms ,form2 appear just for a second
     
  2. dotNet Zombie

    dotNet Zombie New Member

    Joined:
    Aug 28, 2010
    Messages:
    34
    Likes Received:
    10
    Trophy Points:
    0
    Occupation:
    .Net Developers
    Location:
    Minnesota
    Home Page:
    http://www.dotnetzombie.net
    If registerUser form is the form called from Program.cs, then it'll exit the application as soon as it closes.

    Instead, just hide it.

    private void REGISTERbtn_Click(object sender, EventArgs e)
    {
    details obj=new details();
    obj.show();
    this.Hide();
    }
     
    blackrubybarb and shabbir like this.
  3. dreskei

    dreskei New Member

    Joined:
    Oct 22, 2010
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    student
    Location:
    delhi
    but this does not close the form ,it hides it....and then again when i run the application....it shows the error coz the application is still not completely closed....the form was only hidden not closed...although we cn continue neglecting that error
     
  4. blackrubybarb

    blackrubybarb New Member

    Joined:
    Oct 28, 2010
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    .NET Developer
    Location:
    Sri Lanka
    try this
    private void REGISTERbtn_Click(object sender, EventArgs e)
    {
    details obj=new details();
    obj.show();
    this.Dispose();
    }
     
  5. dotNet Zombie

    dotNet Zombie New Member

    Joined:
    Aug 28, 2010
    Messages:
    34
    Likes Received:
    10
    Trophy Points:
    0
    Occupation:
    .Net Developers
    Location:
    Minnesota
    Home Page:
    http://www.dotnetzombie.net
    the dispose method will do the same thing as the Close method.

    If you wanted to close the Application when there is a hidden form open, just set up a Form Closing Event that calls this Method: Application.Exit()
     
  6. dreskei

    dreskei New Member

    Joined:
    Oct 22, 2010
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    student
    Location:
    delhi
    it worked....thnx a lot!!
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice