Results 1 to 12 of 12

Thread: [RESOLVED] Adding menu items

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2009
    Posts
    86

    Resolved [RESOLVED] Adding menu items

    Hi,

    I downloaded a nice menu control from this webpage

    http://www.codeproject.com/KB/menus/VistaMenu.aspx.

    I added the control to my toolbox, and dragged and dropped it onto my form.

    The problem is I can't see any way of adding men items.

    There is a property named items, but that doesn't seem to add menu items to the menu. There doesn't seem to be any other property that would add the items.

    I'm also wondering if there is a way of adding code to add the menu items.
    If there is, could someone show me how

    Kareem

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Adding menu items

    Um, did you bother to read the page you linked to?
    Next, populate the menu control, adding menu items. There are several overloaded methods you can use to achieve this:
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Nov 2009
    Posts
    86

    Re: Adding menu items

    Hi.

    Yes Jm I did, but I didn't understand it. What does it mean ?

    I mean I know how to create a normal menu in VB, but this is entirely different.

    Kareem

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Adding menu items

    No, this is not completely different. It is EXACTLY the same. They provide an example right there on the page you downloaded from.
    Code:
          vmcMenu.MenuItems.Add(
                  "Item " + idx,
    	      "Description " + idx,
                   img
           )
    Exactly like the MenuStrip in the .NET Framework, this menu has a property that returns a collection containing the child menu items and that collection has an Add property. This is a pattern that is repeated over and over throughout the .NET Framework and any well-written third-party code. If you know how to use a .NET MenuStrip then you know how to use this menu too.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,714

    Re: adding items to menu control

    Right on the page the author documents the methods

    Code:
    public VistaMenuItem Add(string sText);
    public VistaMenuItem Add(string sText, string sDescription);
    public VistaMenuItem Add(string sText, string sDescription, Image img);
    public VistaMenuItem Add(string sText, Image img);
    public void Add(VistaMenuItem btn);
    Code:
    for(int idx = 0; idx < 5; idx++)
          vmcMenu.MenuItems.Add(
                  "Item " + idx,
    	      "Description " + idx,
                   img
           );

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: adding items to menu control

    Quote Originally Posted by kevininstructor View Post
    Right on the page the author documents the methods

    Code:
    public VistaMenuItem Add(string sText);
    public VistaMenuItem Add(string sText, string sDescription);
    public VistaMenuItem Add(string sText, string sDescription, Image img);
    public VistaMenuItem Add(string sText, Image img);
    public void Add(VistaMenuItem btn);
    Code:
    for(int idx = 0; idx < 5; idx++)
          vmcMenu.MenuItems.Add(
                  "Item " + idx,
    	      "Description " + idx,
                   img
           );
    Which is exactly what I said the first time this question was posted. Please do not, under any circumstances, post the same question twice. It is against forum "rules". If you don't feel you have the information you need then post to your existing thread asking for more information.

    Of course, in this case you already had the information. You just weren't using it.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Nov 2009
    Posts
    86

    Re: Adding menu items

    Hi,

    I probably don't understand menus as well as I thought I did. I wrote the following code


    Imports VistaMenuControl

    Public Class Form1

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim vmcMenu As New VistaMenuControl.VistaMenuControl
    Dim Vmcitem As New VistaMenuItem
    Dim vmcmenuitems As New VistaMenuItems

    Vmcitem..add("button1", "click")


    End Sub
    End Class


    I got an error meassage on the last line of code saying VistaMenuItems is not a member of VistaMenuControl.VistaMenuItem

    I then replaced the last line with the following line

    vmcmenuitems.Add("button1", "click")

    that still didn't work.

    Jm in your last reply, in the sample code what exactly is vmc menu. I mean is it a VistaMenuControl or a VistaMenuItem.

  8. #8
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Adding menu items

    Duplicate threads merged - please post each question (or variation of it) only once.

  9. #9
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,714

    Re: Adding menu items

    Quote Originally Posted by kareem1000 View Post
    Hi,

    I probably don't understand menus as well as I thought I did. I wrote the following code


    Imports VistaMenuControl

    Public Class Form1

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim vmcMenu As New VistaMenuControl.VistaMenuControl
    Dim Vmcitem As New VistaMenuItem
    Dim vmcmenuitems As New VistaMenuItems

    Vmcitem..add("button1", "click")


    End Sub
    End Class


    I got an error meassage on the last line of code saying VistaMenuItems is not a member of VistaMenuControl.VistaMenuItem

    I then replaced the last line with the following line

    vmcmenuitems.Add("button1", "click")

    that still didn't work.

    Jm in your last reply, in the sample code what exactly is vmc menu. I mean is it a VistaMenuControl or a VistaMenuItem.
    The highlighed line has two dots, should only be dot, actaully missing .Item

    I would suggest adding the menu control to the form via the tool window then add items as follows since you can not add items via the property window as per the author of the menu control
    Code:
            Dim Item As New VistaMenuControl.VistaMenuItem(VistaMenuControl1)
            Item.Text = "Add"
            Item.Description = "Add new widget"
            Item.ItemTag = 1
            VistaMenuControl1.Items.Add(Item)

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Nov 2009
    Posts
    86

    Re: Adding menu items

    Hi,

    Just want to clarify a couple of things.

    It seems from what you guys are saying that you can't add a submenu to this type of menu. from example the code that kevininstructor gave me in his last reply, i take it you can't create a submenu off add/add a widget.

    And secondly I didn't know it was against forum rules to post the same twice.
    i didn't know that it was possible to repost the original thread.

    Regards,
    Kareem

  11. #11
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,714

    Re: Adding menu items

    Quote Originally Posted by kareem1000 View Post
    Hi,

    It seems from what you guys are saying that you can't add a submenu to this type of menu. from example the code that kevininstructor gave me in his last reply, i take it you can't create a submenu off add/add a widget.

    Regards,
    Kareem
    This type of menu system does not lend itself to sub-menus and would be awkward if it did.

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Nov 2009
    Posts
    86

    Re: Adding menu items

    Hi,

    Yes, I think fully understood this now. Thanks for you help kevin.

    Kareem.

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