ToolStrip with ToolStripDropDownButton

A

Adam Honek

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
 
G

gene kelley

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
 
A

Adam Honek

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
 
G

gene kelley

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
 
A

Adam Honek

OK thanks.

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

Thanks,
Adam
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top