C# .NET - Call a form another one, and close the first

Asked By Aldo Liaks on 19-Jan-09 08:36 AM
Hi guys,

I have two winform projects in my solution.

The first one is a Logon form.
The second one is the main window.

I want to call the second one (MainWindow) and close the first (Logon), so I am trying as follows, but when doing so, both forms get closed...

How can I work it around?

Thanks in advance,
Aldo.

            private void CallMainForm()  
            {  
                // Close Logon form.  
                this.Close();  
 
                // Get an instance of MainForm.  
                Main.MainWindow mainform = new Main.MainWindow();  
                mainform.Show();  
            } 

Both are not getting closed. Put the this.close() after mainform.show()

[)ia6l0 iii replied to Aldo Liaks on 19-Jan-09 08:42 AM
btw, how many projects are you working on? You seem to be posting so many questions in a day? :-)

Yeap..

Aldo Liaks replied to [)ia6l0 iii on 19-Jan-09 08:59 AM

Today I have a lot of questions... Thanks for helping...

hi

Venkat K replied to Aldo Liaks on 19-Jan-09 12:30 PM

1. Registering Form1.Closing event, cancel it and hide the main form

 

2. Start another thread for the second form:

 

public static void ThreadProc()

{

    Application.Run(new Form());

}

 

private void button1_Click(object sender, EventArgs e)

{

    System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(ThreadProc));

    t.Start();

}

Thanks
Aldo Liaks replied to Venkat K on 20-Jan-09 01:21 AM
Thanks!
Reply
alice johnson replied to Aldo Liaks on 20-Jan-09 11:15 AM

You can use the close property of the form wen u open the second form.

then wen u close the second form use the show property of  the first form.

This will work, try this way:

Here SelectCompany is the first form:

         SelectCompany2 is the second form

SelectCompany2 frmSelectCompany = new SelectCompany2();  

In Forn_closed event of the this form write this code:

{

this.Hide();

frmSelectCompany.ShowDialog();

}

In the closed_Form property of Second form write the code to open the Fisrt form:

SelectCompany  sel=new SelectCompany()

In Forn_closed event of the this form write this code:

{

    sel.ShowDialog();

}


Hope this helped you, let me know if u need more help





saurabh singh replied to Aldo Liaks on 21-Jan-09 04:23 AM
     private void CallMainForm()  
            {  
                // Close Logon form.  
                this.Hide();
 
                // Get an instance of MainForm.  
                Main.MainWindow mainform = new Main.MainWindow();  
                mainform.Show();  
            } 
This is very simple
RAJENDER REDDY PALREDDY replied to Aldo Liaks on 04-Feb-09 03:40 PM

Dear Friend!

   If you take the following code then it works. This is very simple na!

private void CallMainform()

{

   ActiveForm.Hide();

   Main.MainWindow mainform = new Main.MainWindow();

   DailogResult dr = mainform.ShowDailog();

   ActiveForm.Close();

}

Thanks
Aldo Liaks replied to RAJENDER REDDY PALREDDY on 05-Feb-09 01:09 AM
end of post
techminds replied to Aldo Liaks on 21-Feb-10 01:31 PM
 Hi, 
    I have done one windows application in that it has two forms. In the Main Form i added two popup buttons. one is for audio stego other is for Image stego.

1) When Audio Popup button is clicked The Audio Form gets appeared. I used the code below in the AudioForm_Closed event so that i can again return to the Main for to select the Image popup button or Audio popup button
   {
            this.Hide();
            MainForm main = new MainForm();
            main.ShowDialog();
   }
2) But when I close the Audio Form the whole application is getting closed. Can U please help me so that i can migrate between the forms as many times as possible. . and perform the operations

        
techminds replied to techminds on 21-Feb-10 01:34 PM
I tried and used the code below though the Main Form got displayed when i click on any of the button the whole application gets closed

this is the code i wrote in the AudioForm_Closed Event
{
      MainForm mainForm = new MainForm();
            mainForm.Show();
            mainForm.Activate();
}

Can You please help me in the code so that i can navigate between the forms easily. please reply as soon as possible