Hi supriyan,
Check this example. Now please take its reference and correct your code.
Form Design
In the main Form i have added 4 CheckBoxes and a Button.
I have added 4 Form to open on Button Click based on the checked CheckBoxes.
Code
Form1
C#
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.CenterToScreen();
}
private void btnOpen_Click(object sender, EventArgs e)
{
if (chkForm2.Checked)
{
Form2 frm = new Form2();
frm.Show();
}
if (chkForm3.Checked)
{
Form3 frm = new Form3();
frm.Show();
}
if (chkForm4.Checked)
{
Form4 frm = new Form4();
frm.Show();
}
if (chkForm5.Checked)
{
Form5 frm = new Form5();
frm.Show();
}
this.Hide();
}
}
VB.Net
Public Partial Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
Me.CenterToScreen()
End Sub
Private Sub btnOpen_Click(ByVal sender As Object, ByVal e As EventArgs)
If chkForm2.Checked Then
Dim frm As Form2 = New Form2()
frm.Show()
End If
If chkForm3.Checked Then
Dim frm As Form3 = New Form3()
frm.Show()
End If
If chkForm4.Checked Then
Dim frm As Form4 = New Form4()
frm.Show()
End If
If chkForm5.Checked Then
Dim frm As Form5 = New Form5()
frm.Show()
End If
Me.Hide()
End Sub
End Class
Form2
C#
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
this.Size = new Size(280, 250);
this.CenterToScreen();
}
private void Form2_FormClosed(object sender, FormClosedEventArgs e)
{
if (Application.OpenForms.Count == 1)
{
Form1 frm = new Form1();
frm.Show();
}
}
}
VB.Net
Public Partial Class Form2
Inherits Form
Public Sub New()
InitializeComponent()
Me.Size = New Size(280, 250)
Me.CenterToScreen()
End Sub
Private Sub Form2_FormClosed(ByVal sender As Object, ByVal e As FormClosedEventArgs)
If Application.OpenForms.Count = 1 Then
Dim frm As Form1 = New Form1()
frm.Show()
End If
End Sub
End Class
Form3
C#
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
this.Size = new Size(270, 240);
this.CenterToScreen();
}
private void Form3_FormClosed(object sender, FormClosedEventArgs e)
{
if (Application.OpenForms.Count == 1)
{
Form1 frm = new Form1();
frm.Show();
}
}
}
VB.Net
Public Partial Class Form3
Inherits Form
Public Sub New()
InitializeComponent()
Me.Size = New Size(270, 240)
Me.CenterToScreen()
End Sub
Private Sub Form3_FormClosed(ByVal sender As Object, ByVal e As FormClosedEventArgs)
If Application.OpenForms.Count = 1 Then
Dim frm As Form1 = New Form1()
frm.Show()
End If
End Sub
End Class
Form4
C#
public partial class Form4 : Form
{
public Form4()
{
InitializeComponent();
this.Size = new Size(260, 230);
this.CenterToScreen();
}
private void Form4_FormClosed(object sender, FormClosedEventArgs e)
{
if (Application.OpenForms.Count == 1)
{
Form1 frm = new Form1();
frm.Show();
}
}
}
VB.Net
Public Partial Class Form4
Inherits Form
Public Sub New()
InitializeComponent()
Me.Size = New Size(260, 230)
Me.CenterToScreen()
End Sub
Private Sub Form4_FormClosed(ByVal sender As Object, ByVal e As FormClosedEventArgs)
If Application.OpenForms.Count = 1 Then
Dim frm As Form1 = New Form1()
frm.Show()
End If
End Sub
End Class
Form5
C#
public partial class Form5 : Form
{
public Form5()
{
InitializeComponent();
this.Size = new Size(250, 220);
this.CenterToScreen();
}
private void Form5_FormClosed(object sender, FormClosedEventArgs e)
{
if (Application.OpenForms.Count == 1)
{
Form1 frm = new Form1();
frm.Show();
}
}
}
VB.Net
Public Partial Class Form5
Inherits Form
Public Sub New()
InitializeComponent()
Me.Size = New Size(250, 220)
Me.CenterToScreen()
End Sub
Private Sub Form5_FormClosed(ByVal sender As Object, ByVal e As FormClosedEventArgs)
If Application.OpenForms.Count = 1 Then
Dim frm As Form1 = New Form1()
frm.Show()
End If
End Sub
End Class
Screenshot