Results 1 to 6 of 6

Thread: Another newbie question

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2000
    Location
    Nashville, TN
    Posts
    54

    Unhappy

    Lets say you have a menu already. Is there a way to add menus at runtime. could someone post the code. thanks

  2. #2
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    You have to make all the menu's you think you'll need at design time, then change their visible and caption properties to make it look as if your adding them at run time, start them off as invisible and then make them visible.

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 2000
    Location
    Nashville, TN
    Posts
    54
    Thanks Sam

  4. #4
    Addicted Member
    Join Date
    Aug 1999
    Location
    Ottawa,ON,Canada
    Posts
    217
    Not quite true Sam, you can add menus if they are in a Menu Control Array. Except for the top-level entries, any menu item can be in a control array. How do you think, for exmaple, the Windows List works in MDI Forms?

  5. #5
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    I wasn't sure so I didn't mention them.

  6. #6
    Addicted Member
    Join Date
    Aug 1999
    Location
    Ottawa,ON,Canada
    Posts
    217
    Sorry, little mistake, you can also load top-level entries as well, I just did a little test. The only problem is that every top-level entries does not (for obvious reasons) contain the same sub-menus as the first index. Oh yeah, if you were wondering how to do it:
    First, when you create your menu items, you must set the index of the menu that you want created multiples of to zero or some arbitary number, just as long as it knows it is in a control array.
    Now to add a menu item (we'll call the control array Menu item mnuTest) do the following:
    Code:
    Private Sub AddMenuItemTest(sCaption As String)
       Dim iNextIndex As Integer
       
       iNextIndex = mnuTest(mnuTest.UBound).Index + 1
       Call Load(mnuTest(iNextIndex))
       mnuTest(iNextIndex).Caption = sCaption
    End Sub
    Call this as many times as you want to add items. You may also want to extend this function to allow other properties of the new menu item to be passed, such as Enabled and Checked.

    Hope this helps.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width