dcsimg


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 11 of 11

Thread: Multiple MainMenu problem

  1. #1
    Join Date
    Aug 2004
    Posts
    43,023

    Multiple MainMenu problem

    [Originally posted by evgeni]

    I have a Form with 3 MainMenus on it. I am trying to make as follows:

      foreach menu in "MenuCollection"
      menu.some_method

    My Problem is that I do not know where the "MenuCollection" is.
    I cannot create the collection manually.
    I know that all controls on a Form are in Form.Controls, but MainMenu is not.

    To which collection my menus belong to?

    Thanks in advance.


  2. #2
    Join Date
    Aug 2004
    Posts
    43,023

    Re: Multiple MainMenu problem

    [Originally posted by Marcel Slooff]

    Every menu option is a control by itself in VB and does not retain in the Controls collection but in the form itself.
    You can simply use this code for example to loop through all menu's in your form:

    Dim mnuMenu as Menu

    For Each mnuMenu in frmYourForm
    MsgBox mnuMenu.Caption
    Next

    This code will show a message box with the caption of the menu option for each menu in the form.

    Hope this helps ;)

  3. #3
    Join Date
    Aug 2004
    Posts
    43,023

    Re: Multiple MainMenu problem

    [Originally posted by Marcel Slooff]

    Every menu option is a control by itself in VB and does not retain in the Controls collection but in the form itself.
    You can simply use this code for example to loop through all menu's in your form:

    Dim mnuMenu as Menu

    For Each mnuMenu in frmYourForm
    MsgBox mnuMenu.Caption
    Next

    This code will show a message box with the caption of the menu option for each menu in the form.

    Hope this helps ;)

  4. #4
    Join Date
    Aug 2004
    Posts
    43,023

    Re:Re: Multiple MainMenu problem

    [Originally posted by evgeni]

    Thanks for replay.

    As I understand for each statement is looking for specific type among the same types container.
    You are talking to make:
    For Each mnuMenu in frmYourForm
    MsgBox mnuMenu.Caption
    Next
    But it will not work since frmYourForm is not container of MainMenu type.

  5. #5
    Join Date
    Aug 2004
    Posts
    43,023

    Re: Multiple MainMenu problem

    [Originally posted by allen]

    I'm not sure if I follow you but do want to find all the menu controls on your form?

    Try this below:

    Private Sub Command1_Click()
    Dim c As Control
    For Each c In Me.Controls
    If TypeOf c Is Menu Then
    Debug.Print c.Name, c.Caption
    'Other processing here
    End If

    Next


    End Sub


  6. #6
    Join Date
    Aug 2004
    Posts
    43,023

    Re:Re: Multiple MainMenu problem

    [Originally posted by evgeni]

    Thanks for respond.

    The menu is not a part of Me.Controls collection!

  7. #7
    Join Date
    Aug 2004
    Posts
    43,023

    Re:Re:Re: Multiple MainMenu problem

    [Originally posted by Marcel Slooff]

    I am at a loss here what you mean. When creating a menu in a VB form the form itself is the container for the menu since it is an intrinsic part of the form class it is an instance of. If you want to access another form's menu (e.g. a MDI parent) you would just have to substitute the right form. I've tested this example before submitting it and it works fine. But probably I didn't understand your problem. Please explain it more carefully someone else might know a solution.

    Greetz

  8. #8
    Join Date
    Aug 2004
    Posts
    43,023

    Re:Re:Re: Multiple MainMenu problem

    [Originally posted by Marcel Slooff]

    Please try the solutions people give you. This one works too!

  9. #9
    Join Date
    Aug 2004
    Posts
    43,023

    Re:Re:Re: Multiple MainMenu problem

    [Originally posted by allen]

    Then what menu are you looking for??????
    What do mean by "MainMenu" then?
    Please define your terms.

  10. #10
    Join Date
    Aug 2004
    Posts
    43,023

    Re:Re:Re:Re: Multiple MainMenu problem

    [Originally posted by evgeni]

    Oops!

    May be it works in VB but not VB.NET

  11. #11
    Join Date
    Aug 2004
    Posts
    43,023

    Re:Re:Re:Re:Re: Multiple MainMenu problem

    [Originally posted by Marcel Slooff]

    That sure explains a lot ;) Sorry I can't be of assictance for .NET. I've not finished my MCSD for that yet. More luck next time.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center