473,433 Members | 1,866 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,433 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 9148
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 ...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
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
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: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.