Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
Is it possible to call a menuItem from a child form? I can't seem to make it work. Can anyone help?
Being smarter than you look is always better than looking smarter than you are.
  • *Experts*
Posted

You can acces the menu items of the parent by using the MDIParent property of the form:

'lets say you want to change the text...
Me.MdiParent.Menu.MenuItems(0).Text = "New menu text"
'or if you want to click it...
Me.MdiParent.Menu.MenuItems(0).PerformClick()

You just have to change the index to the one you want to use.

Posted
That's what I tried but, it's not working. Any other way to get to it?
Being smarter than you look is always better than looking smarter than you are.
Posted

The comunication beetwin 2 or more forms is not dificult but it must be well thinked before get into a mess in the midle of the project...

 

I use this a lot and I've found 2 ways that are easyest for me...

 

1st: Declare all forms on as shared or on a module so you can have access to them from any other object (Class)... Using this you'll have to start you program in a Sub Main.

 

2nd: This is the one I use most... I create Events on the Forms so that then can comunicate with each other... The MDIParent works as an intermidiate... This way I can modify anything from any form on any form... and it works really well... no errors...

Software bugs are impossible to detect by anybody except the end user.
Posted

mutant - It just does nothing. The event is never called.

 

Alex - Thanks, I'll give that a try and see how she works.

Being smarter than you look is always better than looking smarter than you are.
  • Leaders
Posted

how are you trying to access the parent form? try this...

In Form1 (assuming you have menuitem1 in this case ) ...

   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       Dim frmChild As New Form2()
       frmChild.MdiParent = Me
       frmChild.Show()
   End Sub

   Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem1.Click
       MessageBox.Show("test")
   End Sub

in Form2 ( the child Form ) ...

   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       Dim frmMain As Form1 = Me.MdiParent
       frmMain.MenuItem1.PerformClick()
   End Sub

Posted
I have not tried declaring the parent form that way. I'll give it a try when I get to work on Monday. Thanks!
Being smarter than you look is always better than looking smarter than you are.
Posted

I just like better using Events to do that...

To this simple task, the way dynamic_sysop told really is easyer but it's usual want to comunicate beetwin 2 child forms... and is really good policy to leave each code on its Form so we don't get lost or just duplicate code...

 

It's just a point of view... :D

Software bugs are impossible to detect by anybody except the end user.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...