Enable/Disable Menuitems of MdiParent from MdiChild
-
Hi all, I'm trying to manipulate menuitems of a MdiParent from MdiChild, here's the code that i have frmMain <- the MdiParent Form private void Main_Load(object sender, System.EventArgs e) { frmsignon fs = new frmsignon(); fs.MdiParent = this; fs.Show(); } i'm trying the below code from my MdiChild form to manipulate the menus on my MdiParent form private void frmSignOn_Load(object sender, System.EventArgs e) { frmMain fM = new frmMain(); fM.menuItem1.Enabled = false; } this code has no build errors, but it has no effect upon run time, the menuItem1 of my MdiParent form is still ENABLED. What seems to be missing? Please help me make this work. Thanks in advance:-D
-::maximus::-
-
Hi all, I'm trying to manipulate menuitems of a MdiParent from MdiChild, here's the code that i have frmMain <- the MdiParent Form private void Main_Load(object sender, System.EventArgs e) { frmsignon fs = new frmsignon(); fs.MdiParent = this; fs.Show(); } i'm trying the below code from my MdiChild form to manipulate the menus on my MdiParent form private void frmSignOn_Load(object sender, System.EventArgs e) { frmMain fM = new frmMain(); fM.menuItem1.Enabled = false; } this code has no build errors, but it has no effect upon run time, the menuItem1 of my MdiParent form is still ENABLED. What seems to be missing? Please help me make this work. Thanks in advance:-D
-::maximus::-
use this.Parent Form2 fr2 = (Form2)this.Parent; and make menuItem1 public but better approach is to make function in MDI parent to enable and disable menu item and call function in child using fr2. :)
-
use this.Parent Form2 fr2 = (Form2)this.Parent; and make menuItem1 public but better approach is to make function in MDI parent to enable and disable menu item and call function in child using fr2. :)
Thanks ashuka :-D you mean changing the frmMain fM = new frmMain(); to Form2 fr2 = (Form2)this.Parent; ? menuItem1 is already public.
-::maximus::-
-
Thanks ashuka :-D you mean changing the frmMain fM = new frmMain(); to Form2 fr2 = (Form2)this.Parent; ? menuItem1 is already public.
-::maximus::-
yeah dear :) Ashu Ashish Kasama
-
yeah dear :) Ashu Ashish Kasama
Hmmm... Im getting this error: An unhandled exception of type 'System.InvalidCastException' occurred Additional information: Specified cast is not valid. my code on the MDIChild form looks like this now private void frmSignOn_Load(object sender, System.EventArgs e) { frmMain fM = (frmMain)this.Parent; fM.menuItem1.Enabled = false; }
-::maximus::-
-
Hmmm... Im getting this error: An unhandled exception of type 'System.InvalidCastException' occurred Additional information: Specified cast is not valid. my code on the MDIChild form looks like this now private void frmSignOn_Load(object sender, System.EventArgs e) { frmMain fM = (frmMain)this.Parent; fM.menuItem1.Enabled = false; }
-::maximus::-
where you launch it frmSignOn frm = new frmSignOn(); frm. MdiParent = this; frm.Show(); and at the time of private void frmSignOn_Load(object sender, System.EventArgs e) { frmMain fM = (frmMain)this.MdiParent; fM.menuItem1.Enabled = false; } :)
-
where you launch it frmSignOn frm = new frmSignOn(); frm. MdiParent = this; frm.Show(); and at the time of private void frmSignOn_Load(object sender, System.EventArgs e) { frmMain fM = (frmMain)this.MdiParent; fM.menuItem1.Enabled = false; } :)
Thanks much! :-D it really worked! got what went wrong private void frmSignOn_Load(object sender, System.EventArgs e) { frmMain fM = (frmMain)this.Parent; frmMain fM = (frmMain)this.MdiParent; fM.menuItem1.Enabled = false; } Thanks Ashu :cool: Regards
-::maximus::-
-
Thanks much! :-D it really worked! got what went wrong private void frmSignOn_Load(object sender, System.EventArgs e) { frmMain fM = (frmMain)this.Parent; frmMain fM = (frmMain)this.MdiParent; fM.menuItem1.Enabled = false; } Thanks Ashu :cool: Regards
-::maximus::-
you are welcome :)