473,473 Members | 1,819 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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

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
1 3489
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Philip Townsend | last post by:
I have a datagrid that contains a dropdown list that is part of an EditItemTemplate. I need to run some code when the dropdown list builds in order to preselect an item in the list. Preselecting...
2
by: Niclas Lindblom | last post by:
Hi, I have a datagrid with linkbuttons. I would like to catch the click event when a link button has been clicked and use the string from the text value of the link button in a clientside Java...
6
by: WebMatrix | last post by:
Hello, Here's the situation (I'll try to be brief as possible) I am working on the control which is created dynamically based on XML string. This control consists of a table with number of rows...
24
by: Charles Law | last post by:
When I click a button I don't want the click event to fire. Is this possible? In fact, what I would really like is to be able to intercept the click event, perform some action, and then prevent...
41
by: JohnR | last post by:
In it's simplest form, assume that I have created a usercontrol, WSToolBarButton that contains a button. I would like to eventually create copies of WSToolBarButton dynamically at run time based...
21
by: Ben | last post by:
Hello I have frames set up in an asp.net application and need one frame to refresh another. Seeing as events need to be registered at the time the page is sent from the server, I was wondering...
0
by: Shashank | last post by:
Hi all, I have made a toolbar in c# using toolstrip control. I am using xml file to generate menu at runtime and then binding it to the dropdown button. My problem is that when I click the...
0
by: nraji | last post by:
hi, I have designed a web part using VS 2003 (Web control library template). I need to publish that in share point. Its not like drag and drop the things from toolbar. Every thing I need to do in...
2
by: elijahs | last post by:
This seems like an obvious one but it has me stumped. I have a complex form with a bunch of databound grids and textbox controls. There is a MainMenu control, and a toolbar control with...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.