Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB6 - Toolbar - Button Menus - Accessing 'Click Events'

Status
Not open for further replies.

h4fod

Technical User
Jan 10, 2011
42
GB
Hi
I am OK creating VB6 toolbar 'graphical buttons' using 'Insert Button Menu' Control on the VB Toolbar Active X Control. But having problems with 'sub' buttons created using 'Insert Button Menu' feature on the toolbar's Propert Page. The Style is '5-Dropdown' ie a drop list of menu buttons appeatr adjacent to main button of a group)

I think ive now tried all options of the button obect to do this to no avail - I cant seem to access a buttons - 'sub buttons' click event using their Keys or Index properties! I have indexed and named the 'Keys' for all the sub menu buttons and have created a conventional menu structure for the sub buttons I want to use eg File-Import and File Export.

Am I missing the obvious?
Thanks in anticipation.
 
Something like this should show you the key for the ButtonMenu item you selected...

Code:
Private Sub Toolbar1_ButtonMenuClick(ByVal ButtonMenu As MSComctlLib.ButtonMenu)
   MsgBox ButtonMenu.Key
End Sub
 
Hi
Thanks for reply. Suggestion will work at 'Button Level' but not at 'menu button level'. I have looked at candidate object/ properties/methods but only the button level will return a key value.

Code:
MsgBox Button.Key

There is no equivalent Key method at menu button level. You can access item(s) as follows if menu button index value is referenced but this is of no help if you are looking for a specific event by button key or index.

Code:
'MsgBox Button.ButtonMenus.Item(2)

will, in my case show 'Import File'.
So,still have a problem.

 
Hi
Still issues here. Buttonmenus argument correctly returns 'Export' or 'Import' when either(1) or (2) buttonmenu arguments assigned. But, only on the button(1) click event on the toolbar. The code will not return Key name when any menubutton associated with button(1) is pressed (Export and Import). There is no action at all. Recall these buttons are 'dropdown' type buttons whih appear when the 'down arrow' button is selected located alongside the main button revealing menubuttons Import and Export.

For example, code below correctly shows 'Export'. But not on the Buttonmenu(2) click - On the button(1) click. Hope I havent totally confused you.

Code:
MsgBox tbrToolbarHat.Buttons(1).ButtonMenus(2).Key
 
Which event are you trapping? There is a ButtonClick event and also a ButtonMenuClick event.

Best way I can explain is, add a new toolbar to a blank form, and go to the Property pages of the toolbar. Click the Buttons tab and do the following:
Click "Insert Button" (Index = 1)
Caption = Main Button
Key = MainButton
Style = 5 - tbrDropdown

Click "Insert ButtonMenu" (Index = 1)
Text = Import
Key = Inport

Click "Insert ButtonMenu" again (Index = 2)
Text = Export
Key = Export

Now cut/paste the following, and it should work as expected.

Code:
Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)
   
   Select Case Button.Key
      Case "MainButton"
         MsgBox "User clicked the main button"
   
   End Select
End Sub

Private Sub Toolbar1_ButtonMenuClick(ByVal ButtonMenu As MSComctlLib.ButtonMenu)
   Select Case ButtonMenu.Key
      Case "Import"
         MsgBox "User clicked Import ButtonMenu"
      Case "Export"
         MsgBox "User clicked Export ButtonMenu"
   End Select

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top