Introduction

When I click the menu item I disable it for user so as not to open the same form more than one time:
If the control is on the parent form like button1, I can access it by one single line code
//if the control is on the parent Form Direct
Like button1 I can access it by one single line code
((Form)this.MdiParent).Controls["button1"].Enabled
= true;
But if the control is owned by other control on the parent form, I must access parent form then access the control that hold the Control. I wanna to access like a tree system
Form frm = (Form)this.MdiParent;
MenuStrip ms = (MenuStrip)frm.Controls["menuStrip1"];
ToolStripMenuItem ti = (ToolStripMenuItem)ms.Items["fileToolStripMenuItem"];
ti.DropDownItems["form2ToolStripMenuItem"].Enabled = true;
Now we can customize this code and put it in a class :
class MenuSettings
{
public static void EnableMenuItem(string
MenuName, string MenuItemName)
{
//Access the Parent Form
Form frm = (Form)Application.OpenForms["Form1"];
//Access The MenuStrip Control
MenuStrip ms = (MenuStrip)frm.Controls["menuStrip1"];
//Access The First Level Menu Items
ToolStripMenuItem ti = (ToolStripMenuItem)ms.Items[MenuName];
//Then I use This control As my needs
ti.DropDownItems[MenuItemName].Enabled = true;
}
public static void EnableMenuItem(string
L1MenuItem, string L2MenuItem, string MenuItemName)
{
//Access the Parent Form
Form frm = (Form)Application.OpenForms["Form1"];
//Access The MenuStrip Control
MenuStrip ms = (MenuStrip)frm.Controls["menuStrip1"];
//Access The First Level Menu Items
ToolStripMenuItem ti1 = (ToolStripMenuItem)ms.Items[L1MenuItem];
//Access The Sconed Level Menu Items
ToolStripMenuItem ti2 = (ToolStripMenuItem)ti1.DropDownItems[L2MenuItem];
//Then I use This control As my needs
ti2.DropDownItems[MenuItemName].Enabled = true;
}
}
And use it in any place I want like form closing event:
MenuSettings.EnableMenuItem("fileToolStripMenuItem", "form3ToolStripMenuItem");

MenuSettings.EnableMenuItem("toolsToolStripMenuItem", "styleToolStripMenuItem", "form6ToolStripMenuItem");
Finally I hope it will useful to you. Have a nice time.

Rajkumar GPosted May 7, 2020, 10:13 AM
How do we do in reverse way? like call child form control in MDI form. Can you help me to do this ?
bil cilPosted Oct 12, 2012, 2:24 AM
Hi I see your article. It is good. I have a question. If I want to close a child form from parent form. How can I do? email: [email protected]
satish babuPosted Sep 25, 2012, 4:21 AM
Thank you so much ..even though its 3year old thread it helped me a lot ..exactly this is what I was looking for.
Anoop PVPosted Apr 21, 2012, 3:15 AM
Thanks it helped me..thank u very much
SUPRATIM DASPosted Dec 25, 2009, 8:44 AM
Say me how to make a Keygenerator with backgroubd sound effect in c# My email id is [email protected]