Click here to Skip to main content
15,905,144 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
private void level1ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form2 f2 = new Form2();
            Form3 f3 = new Form3();
            f2.MdiParent = this;
            f3.MdiParent = this;
            f2.Show();                                                   
            f3.Close();                                  
        }

C#
/big>pre>
Posted

1 solution

Use the below code its for Form2 to be open and others should be closed
add namespace using system.Reflection;

C#
private void level1ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //For Form2 Menu Item Click
            Assembly frmAssembly = Assembly.LoadFile(Application.ExecutablePath);
            foreach (Type type in frmAssembly.GetTypes())
            {
                if (type.BaseType == typeof(Form))
                {
                    if (type.Name == "Form2")
                    {
                            Form frmShow = (Form)frmAssembly.CreateInstance(type.ToString());
                            foreach (Form form in this.MdiChildren)
                            {
                                form.Close();
                            }
                            frmShow.MdiParent = this;
                            frmShow.StartPosition = FormStartPosition.CenterScreen;
                            frmShow.Show();
                    }
                }
            }                     
        }
 
Share this answer
 
Comments
Nigol_Learner 8-Dec-15 17:50pm    
You Are Great Bro, It's work, According to below VB code, I just convert to C#, But Why my C# Code didn't work bro, what is the Issue?

Private Sub DownMachineToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles DownMachineToolStripMenuItem.Click
Dim f2 = Form2
f2.MdiParent = Me
f2.Show()
Form3.Close()
Form4.Close()
Form5.Close()
End Sub

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900