Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 17th, 2012, 02:35 AM
reaper7861 reaper7861 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2006
Posts: 44 reaper7861 Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 17 h 14 m 43 sec
Reputation Power: 0
Coding a Menu without the use of the toolbox

As i said i'm coding without the use of the toolbox and i have run into a snag. I need to be able to find out which item im clicking on for the event and i am a little confused as to how to go about this.
Here is what i have so far:
Code:
    Dim mainMenu1 As New MainMenu
    Dim WithEvents menuItem1 As New MenuItem
    Dim WithEvents menuItem2 As New MenuItem

Code:
        'adding a menu
        'changing the text for the first menu item
        menuItem1.Text = "File"
        'changing the text for the second menu item
        menuItem2.Text = "Books"

      
        Menu = mainMenu1

        With mainMenu1
            .MenuItems.Add(menuItem1)
            .MenuItems.Add(menuItem2)

            ' .Items.Add("Clear")
            'menuItem1.MenuItems.Add("Exit")

            'menuItem2.MenuItems.Add("Networking")
            'menuItem2.MenuItems.Add("Programming")
            'menuItem2.MenuItems.Add("Web")
        End With

        With menuItem1
            .MenuItems.Add("Clear")
            .MenuItems.Add("Exit")
        End With

        With menuItem2
            .MenuItems.Add("Networking")
            .MenuItems.Add("Programming")
            .MenuItems.Add("Web")
        End With

Code:
 Private Sub menuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles menuItem1.Click 'i think this is not correct either, maybe need to handle the click differently?
         
        label.Text = menuItem1.Text
'this is where i want to basically put a switch to know which 'item i have selected in the menu to do different actions but do 'not know how to retrieve the individual menu items, such as on menuItem1 how do get the clear item click event?

    End Sub

Thanks in advance for any help.

Reply With Quote
  #2  
Old October 17th, 2012, 02:19 PM
couttsj couttsj is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2011
Posts: 167 couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Days 17 h 26 m 18 sec
Reputation Power: 43
I tried to duplicate what you are doing, but ran into a problem with the first step. When I dimension mainMenu1 as New MainMenu, it is looking for a reference to MainMenu.

J.A. Coutts

Reply With Quote
  #3  
Old October 17th, 2012, 02:37 PM
reaper7861 reaper7861 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2006
Posts: 44 reaper7861 Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 17 h 14 m 43 sec
Reputation Power: 0
ok i figured out what i was doing wrong, i need to add menuitems for each menuitem and then add an event handler for the click.

Please let me know if that makes sense.

Thanks.

Reply With Quote
  #4  
Old October 18th, 2012, 01:06 AM
couttsj couttsj is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2011
Posts: 167 couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level)couttsj User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Days 17 h 26 m 18 sec
Reputation Power: 43
I am still not sure what you are trying to do, but I assume that you want to programmatically add items to a menu. This is usually accomplished using an object array. In the example below, I allow the user to enter a new mailbox name. The first level menu is preloaded, and the first menu item of second level is preloaded into a menu array. The routine then copies the structure of a table to a new table using the new name. A new member of the object array is loaded, and the new name assigned to the caption. The new name and it's index is then stored in the Registry to be loaded automatically the next time the program is loaded. Each menu item has a common name and an associated index. There is a common click event containing the index value:
Private Sub mnuBox_Click(index As Integer)

J.A. Coutts
Code:
Private Sub mnuNew_Click()
    Dim N%
    Dim strTemp As String
    strTemp = InputBox("Enter Name of Mailbox:")
    If Len(strTemp) = 0 Then
        Exit Sub
    Else
        'Check if table already exists
        On Error GoTo Continue
        adoConn1.Execute ("SELECT * FROM " & strTemp & " WHERE 0 = 1;")
        MsgBox strTemp & " already exists!", vbExclamation
        Exit Sub
    End If
Continue: 'Table does not exist yet
    On Error GoTo mnuNewErr
    adoConn1.Execute ("SELECT * INTO " & strTemp & " FROM Dummy WHERE 0 = 1;")
    'If we get this far, the table was sucessfully created
    'Add to menu
    N% = mnuBox.Count
    Load mnuBox(N%)
    mnuBox(N%).Caption = strTemp
    'Add to registry
    Call SaveSettings("Mailbox" & CStr(N%), strTemp)
    Exit Sub
mnuNewErr:
    MsgBox "Error " & CStr(err) & ": " & Error$(err)
End Sub

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > Coding a Menu without the use of the tools

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap