CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Guest

    Dynamic Menu Creation

    How do we append a submenu item to a menu item dynamically. i.e. The way the recently used files are appended. I want to show this submenu which is created dynamically as a popup menu, I shall do this by hiding the main menu item. Is this possible. Please help.


  2. #2
    Join Date
    Mar 1999
    Posts
    9

    Re: Dynamic Menu Creation

    Generally to create dynamic objects you need to start with a array of 1 item at design time with index 0.
    At run time from your code you can load more items of the array by saying

    Load control(i)
    'set properties appropriate for the control
    'make it visible, by default not visible
    'always keep index 0 not visible.

    you can use collection feature on the control array at any time to get the count and process the items in the array.


  3. #3
    Join Date
    Jun 1999
    Location
    Switzerland
    Posts
    58

    Re: Dynamic Menu Creation

    Hi,
    You can dynamically add any type of intrinsic VB control, EXCEPT menu items. Unfortunately, this limitation prevents developers from devising customable menu structures with top-level menus and submenus built on the fly

    Sorry

    Jan


  4. #4
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: Dynamic Menu Creation

    You CAN add menu items dynamically on the fly - as long as their not menus such as :

    Menu1
    Menu2->Menu3 *

    (the menu3 style).


    It is possible to add menus by using the 'Load' command, eg:

    Place a menu on your form called 'mnuFile', caption 'File'. Add a menu beneath this called 'mnuFileItem' with an index of '0'.

    In your form load do :-


    Dim lCount as Long

    for lCount = 1 to 5
    Load mnuFileItem(lCount)
    mnuFileItem(lCount).Visible = true
    mnuFileItem(lCount).Caption = "Item " & lcount
    next




    You could then show this menu as a pop-up whenever the user clicks somewhere on the form, eg:


    private Sub Form_MouseUp(Button as Integer, Shift as Integer, X as Single, Y as Single)
    If Button = vbRightButton then
    PopupMenu mnuFile
    End If

    End Sub






    Steve at http://www.vbaccelerator.com has an excellent Free API menu control (with source-code) that is very easy to use. This allows you to build SubMenu items on the fly (with icons and plenty of fancy highlighting options too!)



    Chris Eastwood

    CodeGuru - the website for developers
    http://www.codeguru.com/vb

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

Featured