MDIChild calling one of it's Parent Form's Menu Items

eramgarden

Contributor
Joined
Mar 8, 2004
Messages
579
Originally from http://www.xtremedotnettalk.net/showthread.php?t=77613

I did this:

In MainForm (parent form), when the form is first loaded :
Code:
mnuView.Enabled = false;

Also created a routine to enable the menus:

Code:
public void enableMenus()
		{
			mnuView.Enabled= true;
			
			
		}


In child form
Code:
frmMDIMain mainframe = new frmMDIMain();
mainframe.enableMenus();

I set debug. It DOES go thru that routine but still wont enable!!
Any ideas??
 
Last edited by a moderator:
You need to refer to the current instance of the parent form - not create a new instance.
Read over some of the above posts as they tell you what you need to do.
 
I'm assuming that you want to enable/desable the menus from an MDI Child form...
In this case you can simply use the MDIParent property to get a pointer to the form. Tho, to use embeded method public void enableMenus() you need to cast the type... something like:

Visual Basic:
'Assume that:
'     - this code is runned on a child form called frmChild
'     - the parent MDI Form is called frmMain
'This can be placed wherever you need to enable the menus.

dim _frmMain as frmMain
_frmMain = me.MDIParent
_frmMain.enableMenus

or simply:
Visual Basic:
DirectCast(me.MDIParent,frmMain).enableMenus

Alex :p
 
Yeah, but still light bulb is dim..

If I do this in ChildForm, it works:
Code:
this.MdiParent.Menu.MenuItems[4].Enabled= true;

But I want to use the method mentioned above..

I am following the example...
In Childform ..I did this:
Code:
frmMDIMain frmMain = this.MdiParent;

But get an error. I do have all that frmchild.show like this:
Code:
private void menuOpenDB_Click(object sender, System.EventArgs e)
		{
			frmDatabaseOpen objDatabaseOpen = new frmDatabaseOpen();
			objDatabaseOpen.MdiParent= this;
			objDatabaseOpen.Show();
		}

but still no luck..found other examples but in VB and when I convert them, they dont work..
 
Oh, I GOT IT...


((frmMDIMain)this.MdiParent).enableMenus();


In child menu.

THANK YOU SO MUCH for your help!
 
Back
Top