First thing is to understand that when you create a WinForm app, and launch it, the Form it launches in the Program.cs 'Main method ... referred to as the 'Main Form' ... when it's closed ... will close the Application, and all other Forms the app has opened.
So, you could do this:
1. have the app launch what is now your second form as its main form.
2. hide the main form window, and show what is now your main form
3. when the secondary form is closed, show the main form:
using System;
using System.ComponentModel;
using System.Windows.Forms;
namespace TwoFormApp
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
SuspendLayout();
}
private SecondaryForm sForm;
private void Form1_Load(object sender, EventArgs e)
{
sForm = new SecondaryForm();
sForm.Closing += SFormOnClosing;
sForm.Show();
}
private void SFormOnClosing(object sender, CancelEventArgs cancelEventArgs)
{
this.Show();
}
private void MainForm_Shown(object sender, EventArgs e)
{
this.Hide();
ResumeLayout();
}
}
}
The WinForm App will allow you to hide the main form only when the 'Shown event is triggered during the start-ui process.
Note: I doubt you are going to want to close the second Form shown (now, your main form) without getting/saving.using some data the user entered/selected on that form ... do you know how to do that ?