473,397 Members | 1,985 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

ToolStrip with ToolStripDropDownButton

I have a ToolStrip.

The ToolStrip has a ToolStripDropDownButton with 3 ToolStripMenuItems

My question is how do I catch the click event ot these 3 ToolStripMenuItems?

I tried the below but it doesn't catch the events:

Private Sub LowPriorityToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
NormalPriorityToolStripMenuItem.Click, _

HighPriorityToolStripMenuItem.Click

'Declare an object of type ToolStripMenuItem

Dim pMenuStripItem As ToolStripMenuItem

'Now let's find out which menu item was clicked

pMenuStripItem = CType(sender, ToolStripMenuItem)

etc. etc.

Should I first declare it as ToolStripDropDownButton? But then how do I get
the event of each ToolStripMenuItem?

Thanks,

Adam
May 8 '06 #1
4 9144
On Mon, 8 May 2006 04:20:45 +0100, "Adam Honek"
<Ad*******@Webmaster2001.freeserve.co.uk> wrote:
I have a ToolStrip.

The ToolStrip has a ToolStripDropDownButton with 3 ToolStripMenuItems

My question is how do I catch the click event ot these 3 ToolStripMenuItems?

I tried the below but it doesn't catch the events:

Private Sub LowPriorityToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
NormalPriorityToolStripMenuItem.Click, _

HighPriorityToolStripMenuItem.Click

'Declare an object of type ToolStripMenuItem

Dim pMenuStripItem As ToolStripMenuItem

'Now let's find out which menu item was clicked

pMenuStripItem = CType(sender, ToolStripMenuItem)

etc. etc.

Should I first declare it as ToolStripDropDownButton? But then how do I get
the event of each ToolStripMenuItem?

Thanks,

Adam


If you are wanting to use a single Sub to handle the
DropDownMenuItems, then just create a Sub similar to this (the three
DropDownItems are named, MenuItem1, MenuItem2, MenuItem3, each with a
unique text string ). In this case the DropDownItem click events,
themselves, are not used:

Private Sub WhichMenuItem(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MenuItem1.Click, MenuItem2.Click,
MenuItem3.Click
Dim MenuItem As ToolStripMenuItem = DirectCast(sender,
ToolStripMenuItem)
MessageBox.Show(MenuItem.Name)
'or
MessageBox.Show(MenuItem.Text)

'Use a Select Case statment on the "Name" or "Text" value

End Sub

Gene
May 8 '06 #2
Many thanks,

Works a treat.

Only problem is when I do
pMenuStripItem.Checked = True

I get graphical corruption instead of a tick. It's an orange rectangle with
a very tiny tick in it.

I tried to make it bold instead so the user knows which is currently active
however the bold and font properties are read only.

Anything else I can use to mark the selection?

Thanks,

Adam

"gene kelley" <ok**@by.me> wrote in message
news:ca********************************@4ax.com...
On Mon, 8 May 2006 04:20:45 +0100, "Adam Honek"
<Ad*******@Webmaster2001.freeserve.co.uk> wrote:
I have a ToolStrip.

The ToolStrip has a ToolStripDropDownButton with 3 ToolStripMenuItems

My question is how do I catch the click event ot these 3
ToolStripMenuItems?

I tried the below but it doesn't catch the events:

Private Sub LowPriorityToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
NormalPriorityToolStripMenuItem.Click, _

HighPriorityToolStripMenuItem.Click

'Declare an object of type ToolStripMenuItem

Dim pMenuStripItem As ToolStripMenuItem

'Now let's find out which menu item was clicked

pMenuStripItem = CType(sender, ToolStripMenuItem)

etc. etc.

Should I first declare it as ToolStripDropDownButton? But then how do I
get
the event of each ToolStripMenuItem?

Thanks,

Adam


If you are wanting to use a single Sub to handle the
DropDownMenuItems, then just create a Sub similar to this (the three
DropDownItems are named, MenuItem1, MenuItem2, MenuItem3, each with a
unique text string ). In this case the DropDownItem click events,
themselves, are not used:

Private Sub WhichMenuItem(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MenuItem1.Click, MenuItem2.Click,
MenuItem3.Click
Dim MenuItem As ToolStripMenuItem = DirectCast(sender,
ToolStripMenuItem)
MessageBox.Show(MenuItem.Name)
'or
MessageBox.Show(MenuItem.Text)

'Use a Select Case statment on the "Name" or "Text" value

End Sub

Gene

May 8 '06 #3
On Mon, 8 May 2006 06:09:49 +0100, "Adam Honek"
<Ad*******@Webmaster2001.freeserve.co.uk> wrote:
Many thanks,

Works a treat.

Only problem is when I do
pMenuStripItem.Checked = True

I get graphical corruption instead of a tick. It's an orange rectangle with
a very tiny tick in it.

I tried to make it bold instead so the user knows which is currently active
however the bold and font properties are read only.

Anything else I can use to mark the selection?

Thanks,

Adam

In the example I gave:

MenuItem.Checked = True

Renders a checked menu item as expected which is an orange rectangle
filled with a check mark character - the normal XP style. AFAIK, the
check box graphic has no relation to fonts.

Of course, if using checked items and you only want one item checked,
you will have to clear all the checked items before the Select Case
statement. In the previous example, you could add something like:

Dim c_MenuItem As ToolStripMenuItem
For Each c_MenuItem In
Me.ToolStripDropDownButton1.DropDownItems
c_MenuItem.Checked = False
Next

where "ToolStripDropDownButton1" was the name of the DropDown.
In this type of situation, rather than a checked item, I have a
particular, same icon on each of the menu items and simply toggle the
icon to it's "selected" version to indicate which item is in use.
Gene



"gene kelley" <ok**@by.me> wrote in message
news:ca********************************@4ax.com.. .
On Mon, 8 May 2006 04:20:45 +0100, "Adam Honek"
<Ad*******@Webmaster2001.freeserve.co.uk> wrote:
I have a ToolStrip.

The ToolStrip has a ToolStripDropDownButton with 3 ToolStripMenuItems

My question is how do I catch the click event ot these 3
ToolStripMenuItems?

I tried the below but it doesn't catch the events:

Private Sub LowPriorityToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
NormalPriorityToolStripMenuItem.Click, _

HighPriorityToolStripMenuItem.Click

'Declare an object of type ToolStripMenuItem

Dim pMenuStripItem As ToolStripMenuItem

'Now let's find out which menu item was clicked

pMenuStripItem = CType(sender, ToolStripMenuItem)

etc. etc.

Should I first declare it as ToolStripDropDownButton? But then how do I
get
the event of each ToolStripMenuItem?

Thanks,

Adam


If you are wanting to use a single Sub to handle the
DropDownMenuItems, then just create a Sub similar to this (the three
DropDownItems are named, MenuItem1, MenuItem2, MenuItem3, each with a
unique text string ). In this case the DropDownItem click events,
themselves, are not used:

Private Sub WhichMenuItem(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MenuItem1.Click, MenuItem2.Click,
MenuItem3.Click
Dim MenuItem As ToolStripMenuItem = DirectCast(sender,
ToolStripMenuItem)
MessageBox.Show(MenuItem.Name)
'or
MessageBox.Show(MenuItem.Text)

'Use a Select Case statment on the "Name" or "Text" value

End Sub

Gene

May 8 '06 #4
OK thanks.

I get graphical corruption if I go for the checked method hence went for the
icons instead.

Thanks,
Adam

"gene kelley" <ok**@by.me> wrote in message
news:vq********************************@4ax.com...
On Mon, 8 May 2006 06:09:49 +0100, "Adam Honek"
<Ad*******@Webmaster2001.freeserve.co.uk> wrote:
Many thanks,

Works a treat.

Only problem is when I do
pMenuStripItem.Checked = True

I get graphical corruption instead of a tick. It's an orange rectangle
with
a very tiny tick in it.

I tried to make it bold instead so the user knows which is currently
active
however the bold and font properties are read only.

Anything else I can use to mark the selection?

Thanks,

Adam


In the example I gave:

MenuItem.Checked = True

Renders a checked menu item as expected which is an orange rectangle
filled with a check mark character - the normal XP style. AFAIK, the
check box graphic has no relation to fonts.

Of course, if using checked items and you only want one item checked,
you will have to clear all the checked items before the Select Case
statement. In the previous example, you could add something like:

Dim c_MenuItem As ToolStripMenuItem
For Each c_MenuItem In
Me.ToolStripDropDownButton1.DropDownItems
c_MenuItem.Checked = False
Next

where "ToolStripDropDownButton1" was the name of the DropDown.
In this type of situation, rather than a checked item, I have a
particular, same icon on each of the menu items and simply toggle the
icon to it's "selected" version to indicate which item is in use.
Gene



"gene kelley" <ok**@by.me> wrote in message
news:ca********************************@4ax.com. ..
On Mon, 8 May 2006 04:20:45 +0100, "Adam Honek"
<Ad*******@Webmaster2001.freeserve.co.uk> wrote:

I have a ToolStrip.

The ToolStrip has a ToolStripDropDownButton with 3 ToolStripMenuItems

My question is how do I catch the click event ot these 3
ToolStripMenuItems?

I tried the below but it doesn't catch the events:

Private Sub LowPriorityToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
NormalPriorityToolStripMenuItem.Click, _

HighPriorityToolStripMenuItem.Click

'Declare an object of type ToolStripMenuItem

Dim pMenuStripItem As ToolStripMenuItem

'Now let's find out which menu item was clicked

pMenuStripItem = CType(sender, ToolStripMenuItem)

etc. etc.

Should I first declare it as ToolStripDropDownButton? But then how do I
get
the event of each ToolStripMenuItem?

Thanks,

Adam
If you are wanting to use a single Sub to handle the
DropDownMenuItems, then just create a Sub similar to this (the three
DropDownItems are named, MenuItem1, MenuItem2, MenuItem3, each with a
unique text string ). In this case the DropDownItem click events,
themselves, are not used:

Private Sub WhichMenuItem(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MenuItem1.Click, MenuItem2.Click,
MenuItem3.Click
Dim MenuItem As ToolStripMenuItem = DirectCast(sender,
ToolStripMenuItem)
MessageBox.Show(MenuItem.Name)
'or
MessageBox.Show(MenuItem.Text)

'Use a Select Case statment on the "Name" or "Text" value

End Sub

Gene

May 8 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: GatorBait | last post by:
Hi all, I'm using the new ToolStrip control in a project and I'm running into a problem that I'm hoping someone can help me with. I am building the toolstrip in code by adding buttons,...
0
by: gene kelley | last post by:
I'm migrating/rewriting one of my VB6 apps to VB2005. In the process, I'm trying to avoid using third party activex controls used in the VB6 project. One of the third party controls in the VB6...
5
by: Priya | last post by:
I accidentally deleted the toolstrip which had the ToolStripDropDownButton. Is there a easy way to get it back. The code for the toolstrip still exists, its just that I cant see it in the...
1
by: Adam Honek | last post by:
Hi, I have a toolstrip on a form. One of the parts that comprise this toolstrip is a ToolStripDropDownButton I'm trying to catch these events but somehow it's not working how. I'm using the...
1
by: Dean Slindee | last post by:
I have a toolStripDropDownButton with child toolStripDropDownMenuItems. I would like to iterate thru the toolStripDropDownMenuItems and look at the menuitems and discard the separators. Problem...
0
by: Martijn Mulder | last post by:
The ToolStrip on top of my form is to small. I want to increase its height. Simply setting the Height-property doesn't change the height, though. So I tried to place the ToolStrip in a...
6
by: Mike | last post by:
I have a program that is crashing on some machines (at a client of ours). I have determined that it goes down on this line of code: ToolStrip x = new ToolStrip(); I created a simple test app...
2
SammyB
by: SammyB | last post by:
I have a ToolStrip control on a windows app that contains a ToolStripDropDownButton. When the button is pressed, I would like the menu to display just icons for each choice with no text. If I...
0
by: CNSZU | last post by:
Hello all, Does anyone know how to attach a datasource to a combobox that resides in a toolstripdropdownbutton? With fMain.ToolStripComboBox1.ComboBox .DataSource = dv ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.