Mothra Posted October 2, 2003 Posted October 2, 2003 Is it possible to call a menuItem from a child form? I can't seem to make it work. Can anyone help? Quote Being smarter than you look is always better than looking smarter than you are.
*Experts* mutant Posted October 2, 2003 *Experts* Posted October 2, 2003 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. Quote
Mothra Posted October 2, 2003 Author Posted October 2, 2003 That's what I tried but, it's not working. Any other way to get to it? Quote Being smarter than you look is always better than looking smarter than you are.
*Experts* mutant Posted October 2, 2003 *Experts* Posted October 2, 2003 How is it not working? Is it giving errors or what? :) Quote
AlexCode Posted October 3, 2003 Posted October 3, 2003 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... Quote Software bugs are impossible to detect by anybody except the end user.
Mothra Posted October 4, 2003 Author Posted October 4, 2003 mutant - It just does nothing. The event is never called. Alex - Thanks, I'll give that a try and see how she works. Quote Being smarter than you look is always better than looking smarter than you are.
Leaders dynamic_sysop Posted October 4, 2003 Leaders Posted October 4, 2003 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 Quote
Mothra Posted October 4, 2003 Author Posted October 4, 2003 I have not tried declaring the parent form that way. I'll give it a try when I get to work on Monday. Thanks! Quote Being smarter than you look is always better than looking smarter than you are.
*Gurus* divil Posted October 6, 2003 *Gurus* Posted October 6, 2003 It's worth pointing out that if you have Option Strict On (which you should) you'll have to replace this line Dim frmMain As Form1 = Me.MdiParent with this: Dim frmMain As Form1 = DirectCast(Me.MdiParent, Form1) Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
AlexCode Posted October 6, 2003 Posted October 6, 2003 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 Quote Software bugs are impossible to detect by anybody except the end user.
Mothra Posted October 6, 2003 Author Posted October 6, 2003 Thank you all very much. It's working like a champ now! Quote Being smarter than you look is always better than looking smarter than you are.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.