Assume:
1. Form A is your main form in a Win Form Application.
2. Form A will create Form B.
3. There's a Button on Form A that if clicked will hide Form A and show Form B
4. There's a Button on Form B that if clicked will hide Form B and show Form A.
5. The Form that is hidden should not show in the TaskBar.
Form A:
public partial class FormA : Form
{
public FormA()
{
InitializeComponent();
}
FormB B = new FormB();
private void Form1_Load(object sender, EventArgs e)
{
this.ShowInTaskbar = true;
B.FormBBtn.Click += btnShowA_Click;
}
private void btnShowB_Click(object sender, EventArgs e)
{
this.ShowInTaskbar = false;
this.Hide();
B.ShowInTaskbar = true;
B.Show();
}
private void btnShowA_Click(object sender, EventArgs e)
{
B.ShowInTaskbar = false;
B.Hide();
this.ShowInTaskbar = true;
this.Show();
}
}
Form B:
public partial class FormB : Form
{
public FormB()
{
InitializeComponent();
FormBBtn = btnShowA;
}
public Button FormBBtn { get; private set; }
}
Note that we
must set the reference to Form B's Button in Form B's Constructor because the instance of Form A needs access to it
before the Load Event for Form B will be triggered in order to subscribe to Form B' Button Click Event.