By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,081 Members | 861 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,081 IT Pros & Developers. It's quick & easy.

on click event for item on a dropdown button control on toolbar

P: n/a
Somehow I'm just missing something.

I don't know how to catch when a user clicks on an item in a dropdown list
for a dropdown style button on a toolbar.

I create a new app. Form1. Add a toolbar. Add a button and make it's
style dropdown. In the code I create a contextmenu and add three items.

This is all fine. But when I click on one of the menu items I can't figure
out how to know it's been clicked and what menu item it is.

Here's the test code:

Public Class Form1

Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()

MyBase.New()

'This call is required by the Windows Form Designer.

InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)

If disposing Then

If Not (components Is Nothing) Then

components.Dispose()

End If

End If

MyBase.Dispose(disposing)

End Sub

'Required by the Windows Form Designer

Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer

'It can be modified using the Windows Form Designer.

'Do not modify it using the code editor.

Friend WithEvents ToolBar1 As System.Windows.Forms.ToolBar

Friend WithEvents ToolBarButton1 As System.Windows.Forms.ToolBarButton

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

Me.ToolBar1 = New System.Windows.Forms.ToolBar

Me.ToolBarButton1 = New System.Windows.Forms.ToolBarButton

Me.SuspendLayout()

'

'ToolBar1

'

Me.ToolBar1.Buttons.AddRange(New System.Windows.Forms.ToolBarButton()
{Me.ToolBarButton1})

Me.ToolBar1.DropDownArrows = True

Me.ToolBar1.Location = New System.Drawing.Point(0, 0)

Me.ToolBar1.Name = "ToolBar1"

Me.ToolBar1.ShowToolTips = True

Me.ToolBar1.Size = New System.Drawing.Size(456, 42)

Me.ToolBar1.TabIndex = 0

'

'ToolBarButton1

'

Me.ToolBarButton1.Style =
System.Windows.Forms.ToolBarButtonStyle.DropDownBu tton

Me.ToolBarButton1.Text = "test"

'

'Form1

'

Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)

Me.ClientSize = New System.Drawing.Size(456, 334)

Me.Controls.Add(Me.ToolBar1)

Me.Name = "Form1"

Me.Text = "Form1"

Me.ResumeLayout(False)

End Sub

#End Region

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles MyBase.Load

Dim cm As New ContextMenu

cm.MenuItems.Add("one")

cm.MenuItems.Add("two")

ToolBar1.Buttons(0).DropDownMenu = cm

End Sub

End Class
Nov 21 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi Curtis
What you should be handing is the MenuItem click event , you could create
a separate handler that handles the click on each of the menu items of
your context menu , your handler should be something like that
Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MenuItem1.Click
MessageBox.Show("Source Control: " & CType(sender,
MenuItem).Parent.GetContextMenu().SourceControl.To String)
'If ContextMenu1.SourceControl Is Nothing Then
'MessageBox.Show("Yes")
'Else
' MessageBox.Show(ContextMenu1.SourceControl.Name)
'End If

End Sub
in this example you see you can get also the source control ( if you are
using the menu with more than one control) . you would know under with
control this item was clicked
Hope this helps

Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC

Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.