tootip or microhelp for menu items

G

gs

I was able to set tooltips on objects other than main menu.
I would like to get the effect of tooltip or microhelp in the bottom status
bar when the mouse is hovering over a submenu item.

How do I do that?
For example in outlook express, when one expand a main menu item and holds
mouse over one of the enable sub menu item, one would see some sort
microhelp text in the status bar in the bottom
 
G

gs

I sort of find a way to make the tag value appear in a status bar but it is
far cry form automatic use of tag.


For each submenu time I have an event handler for select..

will be nice to add select event for submenu item in the instance call and
use the tag. but with the shallow knowledge that I have vb, I don't have a
clue yet.


any concrete suggestion?
 
R

RobinS

gs said:
I sort of find a way to make the tag value appear in a status bar but it is
far cry form automatic use of tag.


For each submenu time I have an event handler for select..

will be nice to add select event for submenu item in the instance call and
use the tag. but with the shallow knowledge that I have vb, I don't have a
clue yet.


any concrete suggestion?

I'm not exactly sure if these are the same requests. Here is how to display
status text when someone hovers over the items in a menu strip or toolstrip.
This handles one level of dropdowns; if you have more, you need to use
recursion. Also, this only adds the events when the [tag] property is not
blank, and it displays the tag in the status strip.

You could enable tooltips on the menu items if you want tool tips. That's an
entirely different thing from displaying info in the status strip.

To do this, you need to add handlers for each item for the MouseEnter event
(to set the text) and the MouseLeave event (to blank it back out).

I am calling AddToolStripEventHandlers and AddMenuStripEventHandlers in my
Form_Load event. You could combine these.

Private Sub AddToolStripEventHandlers(ByVal tsToolStrip As ToolStrip)
For Each item As ToolStripItem In tsToolStrip.Items
If item.Tag IsNot Nothing Then
AddHandler item.MouseEnter, AddressOf MenuItem_MouseEnter
AddHandler item.MouseLeave, AddressOf MenuItem_MouseLeave
End If
Next
End Sub
Private Sub AddMenuStripEventHandlers(ByVal msMenuStrip As MenuStrip)
For Each item As ToolStripMenuItem In msMenuStrip.Items
If item.Tag IsNot Nothing Then
AddHandler item.MouseEnter, AddressOf MenuItem_MouseEnter
AddHandler item.MouseLeave, AddressOf MenuItem_MouseLeave
End If
'if you have dropdown menus inside your dropdown menus,
' you would probably want to make a recursive routine to handle
that
If item.DropDownItems.Count > 0 Then
For i As Integer = 0 To item.DropDownItems.Count - 1
Dim ddItem As ToolStripItem
ddItem = item.DropDownItems(i)
If ddItem.Tag IsNot Nothing Then
AddHandler ddItem.MouseEnter, AddressOf
MenuItem_MouseEnter
AddHandler ddItem.MouseLeave, AddressOf
MenuItem_MouseLeave
End If
Next
End If
Next
End Sub

Private Sub MenuItem_MouseEnter(ByVal sender As Object, ByVal e As
EventArgs)
If TypeOf sender Is ToolStripButton Then
Dim ctrl As ToolStripButton = DirectCast(sender,
ToolStripButton)
Me.ToolStripStatusLabel.Text = ctrl.Tag.ToString
ElseIf TypeOf sender Is ToolStripMenuItem Then
Dim ctrl As ToolStripMenuItem = DirectCast(sender,
ToolStripMenuItem)
Me.ToolStripStatusLabel.Text = ctrl.Tag.ToString
End If
End Sub

Private Sub MenuItem_MouseLeave(ByVal sender As Object, ByVal e As
EventArgs)
Me.ToolStripStatusLabel.Text = String.Empty
End Sub

Robin
 
G

GS

thank you.

I tired to deal with next level but failed as toolStripItem does not have
dropdownItems, neither does menuStripItems.

I tried ctype but did not get to work either. all I need now is one more
level for ToolStripMenuItems.

RobinS said:
gs said:
I sort of find a way to make the tag value appear in a status bar but it is
far cry form automatic use of tag.


For each submenu time I have an event handler for select..

will be nice to add select event for submenu item in the instance call and
use the tag. but with the shallow knowledge that I have vb, I don't have a
clue yet.


any concrete suggestion?

I'm not exactly sure if these are the same requests. Here is how to display
status text when someone hovers over the items in a menu strip or toolstrip.
This handles one level of dropdowns; if you have more, you need to use
recursion. Also, this only adds the events when the [tag] property is not
blank, and it displays the tag in the status strip.

You could enable tooltips on the menu items if you want tool tips. That's an
entirely different thing from displaying info in the status strip.

To do this, you need to add handlers for each item for the MouseEnter event
(to set the text) and the MouseLeave event (to blank it back out).

I am calling AddToolStripEventHandlers and AddMenuStripEventHandlers in my
Form_Load event. You could combine these.

Private Sub AddToolStripEventHandlers(ByVal tsToolStrip As ToolStrip)
For Each item As ToolStripItem In tsToolStrip.Items
If item.Tag IsNot Nothing Then
AddHandler item.MouseEnter, AddressOf MenuItem_MouseEnter
AddHandler item.MouseLeave, AddressOf MenuItem_MouseLeave
End If
Next
End Sub
Private Sub AddMenuStripEventHandlers(ByVal msMenuStrip As MenuStrip)
For Each item As ToolStripMenuItem In msMenuStrip.Items
If item.Tag IsNot Nothing Then
AddHandler item.MouseEnter, AddressOf MenuItem_MouseEnter
AddHandler item.MouseLeave, AddressOf MenuItem_MouseLeave
End If
'if you have dropdown menus inside your dropdown menus,
' you would probably want to make a recursive routine to handle
that
If item.DropDownItems.Count > 0 Then
For i As Integer = 0 To item.DropDownItems.Count - 1
Dim ddItem As ToolStripItem
ddItem = item.DropDownItems(i)
If ddItem.Tag IsNot Nothing Then
AddHandler ddItem.MouseEnter, AddressOf
MenuItem_MouseEnter
AddHandler ddItem.MouseLeave, AddressOf
MenuItem_MouseLeave
End If
Next
End If
Next
End Sub

Private Sub MenuItem_MouseEnter(ByVal sender As Object, ByVal e As
EventArgs)
If TypeOf sender Is ToolStripButton Then
Dim ctrl As ToolStripButton = DirectCast(sender,
ToolStripButton)
Me.ToolStripStatusLabel.Text = ctrl.Tag.ToString
ElseIf TypeOf sender Is ToolStripMenuItem Then
Dim ctrl As ToolStripMenuItem = DirectCast(sender,
ToolStripMenuItem)
Me.ToolStripStatusLabel.Text = ctrl.Tag.ToString
End If
End Sub

Private Sub MenuItem_MouseLeave(ByVal sender As Object, ByVal e As
EventArgs)
Me.ToolStripStatusLabel.Text = String.Empty
End Sub

Robin
 
R

RobinS

You're right; I tried to figure out how to do it, but it's not
inherently obvious. I've searched all over, and can't find
anything that tells how to enumerate through all the items
in all the levels of a MenuStrip.

Why don't you use tooltips instead? If you enable the property
"Show Item Tooltips" for the Menu Strip, and then fill in the
tool tips for each option, they will be displayed when you hover
over the menu option.

The only other thing I can think of is to add the options to
the menustrip programmatically, and as you do that, add the
events.

Good Luck.
Robin S.


GS said:
thank you.

I tired to deal with next level but failed as toolStripItem does not have
dropdownItems, neither does menuStripItems.

I tried ctype but did not get to work either. all I need now is one more
level for ToolStripMenuItems.

RobinS said:
gs said:
I sort of find a way to make the tag value appear in a status bar but it is
far cry form automatic use of tag.


For each submenu time I have an event handler for select..

will be nice to add select event for submenu item in the instance call and
use the tag. but with the shallow knowledge that I have vb, I don't
have a
clue yet.


any concrete suggestion?


I was able to set tooltips on objects other than main menu.
I would like to get the effect of tooltip or microhelp in the bottom
status bar when the mouse is hovering over a submenu item.

How do I do that?
For example in outlook express, when one expand a main menu item and
holds mouse over one of the enable sub menu item, one would see some sort
microhelp text in the status bar in the bottom

I'm not exactly sure if these are the same requests. Here is how to display
status text when someone hovers over the items in a menu strip or toolstrip.
This handles one level of dropdowns; if you have more, you need to use
recursion. Also, this only adds the events when the [tag] property is not
blank, and it displays the tag in the status strip.

You could enable tooltips on the menu items if you want tool tips. That's an
entirely different thing from displaying info in the status strip.

To do this, you need to add handlers for each item for the MouseEnter event
(to set the text) and the MouseLeave event (to blank it back out).

I am calling AddToolStripEventHandlers and AddMenuStripEventHandlers in
my
Form_Load event. You could combine these.

Private Sub AddToolStripEventHandlers(ByVal tsToolStrip As ToolStrip)
For Each item As ToolStripItem In tsToolStrip.Items
If item.Tag IsNot Nothing Then
AddHandler item.MouseEnter, AddressOf MenuItem_MouseEnter
AddHandler item.MouseLeave, AddressOf MenuItem_MouseLeave
End If
Next
End Sub
Private Sub AddMenuStripEventHandlers(ByVal msMenuStrip As MenuStrip)
For Each item As ToolStripMenuItem In msMenuStrip.Items
If item.Tag IsNot Nothing Then
AddHandler item.MouseEnter, AddressOf MenuItem_MouseEnter
AddHandler item.MouseLeave, AddressOf MenuItem_MouseLeave
End If
'if you have dropdown menus inside your dropdown menus,
' you would probably want to make a recursive routine to handle
that
If item.DropDownItems.Count > 0 Then
For i As Integer = 0 To item.DropDownItems.Count - 1
Dim ddItem As ToolStripItem
ddItem = item.DropDownItems(i)
If ddItem.Tag IsNot Nothing Then
AddHandler ddItem.MouseEnter, AddressOf
MenuItem_MouseEnter
AddHandler ddItem.MouseLeave, AddressOf
MenuItem_MouseLeave
End If
Next
End If
Next
End Sub

Private Sub MenuItem_MouseEnter(ByVal sender As Object, ByVal e As
EventArgs)
If TypeOf sender Is ToolStripButton Then
Dim ctrl As ToolStripButton = DirectCast(sender,
ToolStripButton)
Me.ToolStripStatusLabel.Text = ctrl.Tag.ToString
ElseIf TypeOf sender Is ToolStripMenuItem Then
Dim ctrl As ToolStripMenuItem = DirectCast(sender,
ToolStripMenuItem)
Me.ToolStripStatusLabel.Text = ctrl.Tag.ToString
End If
End Sub

Private Sub MenuItem_MouseLeave(ByVal sender As Object, ByVal e As
EventArgs)
Me.ToolStripStatusLabel.Text = String.Empty
End Sub

Robin
 
G

GS

Thank you. Now that I have fully converted to menuStrip with
ToolStripMenuItems and that I was finally find the tooltips, I am using
tooltips.

For now the tooltips is good

Nonetheless I would love to find out how to iterate through all the items.
why> eventually I would want the menu text be from resource file for
multi-language interface.




RobinS said:
You're right; I tried to figure out how to do it, but it's not
inherently obvious. I've searched all over, and can't find
anything that tells how to enumerate through all the items
in all the levels of a MenuStrip.

Why don't you use tooltips instead? If you enable the property
"Show Item Tooltips" for the Menu Strip, and then fill in the
tool tips for each option, they will be displayed when you hover
over the menu option.

The only other thing I can think of is to add the options to
the menustrip programmatically, and as you do that, add the
events.

Good Luck.
Robin S.


GS said:
thank you.

I tired to deal with next level but failed as toolStripItem does not have
dropdownItems, neither does menuStripItems.

I tried ctype but did not get to work either. all I need now is one more
level for ToolStripMenuItems.

RobinS said:
I sort of find a way to make the tag value appear in a status bar but
it
is
far cry form automatic use of tag.


For each submenu time I have an event handler for select..

will be nice to add select event for submenu item in the instance
call
and
use the tag. but with the shallow knowledge that I have vb, I don't
have a
clue yet.


any concrete suggestion?


I was able to set tooltips on objects other than main menu.
I would like to get the effect of tooltip or microhelp in the bottom
status bar when the mouse is hovering over a submenu item.

How do I do that?
For example in outlook express, when one expand a main menu item and
holds mouse over one of the enable sub menu item, one would see some sort
microhelp text in the status bar in the bottom



I'm not exactly sure if these are the same requests. Here is how to display
status text when someone hovers over the items in a menu strip or toolstrip.
This handles one level of dropdowns; if you have more, you need to use
recursion. Also, this only adds the events when the [tag] property is not
blank, and it displays the tag in the status strip.

You could enable tooltips on the menu items if you want tool tips.
That's
an
entirely different thing from displaying info in the status strip.

To do this, you need to add handlers for each item for the MouseEnter event
(to set the text) and the MouseLeave event (to blank it back out).

I am calling AddToolStripEventHandlers and AddMenuStripEventHandlers in
my
Form_Load event. You could combine these.

Private Sub AddToolStripEventHandlers(ByVal tsToolStrip As ToolStrip)
For Each item As ToolStripItem In tsToolStrip.Items
If item.Tag IsNot Nothing Then
AddHandler item.MouseEnter, AddressOf MenuItem_MouseEnter
AddHandler item.MouseLeave, AddressOf MenuItem_MouseLeave
End If
Next
End Sub
Private Sub AddMenuStripEventHandlers(ByVal msMenuStrip As MenuStrip)
For Each item As ToolStripMenuItem In msMenuStrip.Items
If item.Tag IsNot Nothing Then
AddHandler item.MouseEnter, AddressOf MenuItem_MouseEnter
AddHandler item.MouseLeave, AddressOf MenuItem_MouseLeave
End If
'if you have dropdown menus inside your dropdown menus,
' you would probably want to make a recursive routine to handle
that
If item.DropDownItems.Count > 0 Then
For i As Integer = 0 To item.DropDownItems.Count - 1
Dim ddItem As ToolStripItem
ddItem = item.DropDownItems(i)
If ddItem.Tag IsNot Nothing Then
AddHandler ddItem.MouseEnter, AddressOf
MenuItem_MouseEnter
AddHandler ddItem.MouseLeave, AddressOf
MenuItem_MouseLeave
End If
Next
End If
Next
End Sub

Private Sub MenuItem_MouseEnter(ByVal sender As Object, ByVal e As
EventArgs)
If TypeOf sender Is ToolStripButton Then
Dim ctrl As ToolStripButton = DirectCast(sender,
ToolStripButton)
Me.ToolStripStatusLabel.Text = ctrl.Tag.ToString
ElseIf TypeOf sender Is ToolStripMenuItem Then
Dim ctrl As ToolStripMenuItem = DirectCast(sender,
ToolStripMenuItem)
Me.ToolStripStatusLabel.Text = ctrl.Tag.ToString
End If
End Sub

Private Sub MenuItem_MouseLeave(ByVal sender As Object, ByVal e As
EventArgs)
Me.ToolStripStatusLabel.Text = String.Empty
End Sub

Robin
 
R

RobinS

I'm glad that worked for you, the tooltips I mean. I would
also like to know how to iterate all the down, and if I ever
figure it out, I'll post it here just for grins.

I thought I saw something in a MSFT article that said
something about using ReadNext to go through them, but
couldn't find it again, so maybe I dreamed it.

Like I said before, the only other thing I could think of
is if you could build the menu from scratch and add the
eventhandlers as you go. What a pain.

You could certainly read the menu info from a file and
create the menu from scratch, complete with the tooltips,
in different languages. Seems like that would be the
kind of thing you'd want to look into that CultureInfo
class for.

Good luck.
Robin S.

GS said:
Thank you. Now that I have fully converted to menuStrip with
ToolStripMenuItems and that I was finally find the tooltips, I am using
tooltips.

For now the tooltips is good

Nonetheless I would love to find out how to iterate through all the items.
why> eventually I would want the menu text be from resource file for
multi-language interface.




RobinS said:
You're right; I tried to figure out how to do it, but it's not
inherently obvious. I've searched all over, and can't find
anything that tells how to enumerate through all the items
in all the levels of a MenuStrip.

Why don't you use tooltips instead? If you enable the property
"Show Item Tooltips" for the Menu Strip, and then fill in the
tool tips for each option, they will be displayed when you hover
over the menu option.

The only other thing I can think of is to add the options to
the menustrip programmatically, and as you do that, add the
events.

Good Luck.
Robin S.


GS said:
thank you.

I tired to deal with next level but failed as toolStripItem does not have
dropdownItems, neither does menuStripItems.

I tried ctype but did not get to work either. all I need now is one more
level for ToolStripMenuItems.


I sort of find a way to make the tag value appear in a status bar but it
is
far cry form automatic use of tag.


For each submenu time I have an event handler for select..

will be nice to add select event for submenu item in the instance call
and
use the tag. but with the shallow knowledge that I have vb, I don't
have
a
clue yet.


any concrete suggestion?


I was able to set tooltips on objects other than main menu.
I would like to get the effect of tooltip or microhelp in the
bottom
status bar when the mouse is hovering over a submenu item.

How do I do that?
For example in outlook express, when one expand a main menu item
and
holds mouse over one of the enable sub menu item, one would see
some
sort
microhelp text in the status bar in the bottom



I'm not exactly sure if these are the same requests. Here is how to
display
status text when someone hovers over the items in a menu strip or
toolstrip.
This handles one level of dropdowns; if you have more, you need to use
recursion. Also, this only adds the events when the [tag] property is not
blank, and it displays the tag in the status strip.

You could enable tooltips on the menu items if you want tool tips. That's
an
entirely different thing from displaying info in the status strip.

To do this, you need to add handlers for each item for the MouseEnter
event
(to set the text) and the MouseLeave event (to blank it back out).

I am calling AddToolStripEventHandlers and AddMenuStripEventHandlers
in
my
Form_Load event. You could combine these.

Private Sub AddToolStripEventHandlers(ByVal tsToolStrip As ToolStrip)
For Each item As ToolStripItem In tsToolStrip.Items
If item.Tag IsNot Nothing Then
AddHandler item.MouseEnter, AddressOf MenuItem_MouseEnter
AddHandler item.MouseLeave, AddressOf MenuItem_MouseLeave
End If
Next
End Sub
Private Sub AddMenuStripEventHandlers(ByVal msMenuStrip As MenuStrip)
For Each item As ToolStripMenuItem In msMenuStrip.Items
If item.Tag IsNot Nothing Then
AddHandler item.MouseEnter, AddressOf MenuItem_MouseEnter
AddHandler item.MouseLeave, AddressOf MenuItem_MouseLeave
End If
'if you have dropdown menus inside your dropdown menus,
' you would probably want to make a recursive routine to
handle
that
If item.DropDownItems.Count > 0 Then
For i As Integer = 0 To item.DropDownItems.Count - 1
Dim ddItem As ToolStripItem
ddItem = item.DropDownItems(i)
If ddItem.Tag IsNot Nothing Then
AddHandler ddItem.MouseEnter, AddressOf
MenuItem_MouseEnter
AddHandler ddItem.MouseLeave, AddressOf
MenuItem_MouseLeave
End If
Next
End If
Next
End Sub

Private Sub MenuItem_MouseEnter(ByVal sender As Object, ByVal e As
EventArgs)
If TypeOf sender Is ToolStripButton Then
Dim ctrl As ToolStripButton = DirectCast(sender,
ToolStripButton)
Me.ToolStripStatusLabel.Text = ctrl.Tag.ToString
ElseIf TypeOf sender Is ToolStripMenuItem Then
Dim ctrl As ToolStripMenuItem = DirectCast(sender,
ToolStripMenuItem)
Me.ToolStripStatusLabel.Text = ctrl.Tag.ToString
End If
End Sub

Private Sub MenuItem_MouseLeave(ByVal sender As Object, ByVal e As
EventArgs)
Me.ToolStripStatusLabel.Text = String.Empty
End Sub

Robin
 
R

RobinS

I got this is from PamelaFluente, and wanted to
post it as a response here in case you don't see
the other posting. The answer to your question
is below.
Thanks again to Pamela.
Robin S
-----------------------------------

Private Sub AddMenuStripEventHandlers(ByVal msMenuStrip As MenuStrip)
RecurseItems(Me.MenuStrip.Items)
End Sub

Sub RecurseItems(ByVal ToolStripItemCollection As ToolStripItemCollection)
Try
For Each ToolStripMenuItemChild As ToolStripMenuItem _
In ToolStripItemCollection
'Debug.Print("I am on " & ToolStripMenuItemChild.Text)
If ToolStripMenuItemChild.Tag IsNot Nothing Then
AddHandler ToolStripMenuItemChild.MouseEnter, _
AddressOf MenuItem_MouseEnter
AddHandler ToolStripMenuItemChild.MouseLeave, _
AddressOf MenuItem_MouseLeave
End If
RecurseItems(ToolStripMenuItemChild.DropDownItems)
Next ToolStripMenuItemChild
Catch ex As InvalidCastException
'ignore it; you'll get this for the separator lines
End Try
End Sub

---------------------------------

RobinS said:
I'm glad that worked for you, the tooltips I mean. I would
also like to know how to iterate all the down, and if I ever
figure it out, I'll post it here just for grins.

I thought I saw something in a MSFT article that said
something about using ReadNext to go through them, but
couldn't find it again, so maybe I dreamed it.

Like I said before, the only other thing I could think of
is if you could build the menu from scratch and add the
eventhandlers as you go. What a pain.

You could certainly read the menu info from a file and
create the menu from scratch, complete with the tooltips,
in different languages. Seems like that would be the
kind of thing you'd want to look into that CultureInfo
class for.

Good luck.
Robin S.

GS said:
Thank you. Now that I have fully converted to menuStrip with
ToolStripMenuItems and that I was finally find the tooltips, I am using
tooltips.

For now the tooltips is good

Nonetheless I would love to find out how to iterate through all the
items.
why> eventually I would want the menu text be from resource file for
multi-language interface.




RobinS said:
You're right; I tried to figure out how to do it, but it's not
inherently obvious. I've searched all over, and can't find
anything that tells how to enumerate through all the items
in all the levels of a MenuStrip.

Why don't you use tooltips instead? If you enable the property
"Show Item Tooltips" for the Menu Strip, and then fill in the
tool tips for each option, they will be displayed when you hover
over the menu option.

The only other thing I can think of is to add the options to
the menustrip programmatically, and as you do that, add the
events.

Good Luck.
Robin S.


thank you.

I tired to deal with next level but failed as toolStripItem does not have
dropdownItems, neither does menuStripItems.

I tried ctype but did not get to work either. all I need now is one more
level for ToolStripMenuItems.


I sort of find a way to make the tag value appear in a status bar
but it
is
far cry form automatic use of tag.


For each submenu time I have an event handler for select..

will be nice to add select event for submenu item in the instance call
and
use the tag. but with the shallow knowledge that I have vb, I don't
have
a
clue yet.


any concrete suggestion?


I was able to set tooltips on objects other than main menu.
I would like to get the effect of tooltip or microhelp in the
bottom
status bar when the mouse is hovering over a submenu item.

How do I do that?
For example in outlook express, when one expand a main menu item
and
holds mouse over one of the enable sub menu item, one would see
some
sort
microhelp text in the status bar in the bottom



I'm not exactly sure if these are the same requests. Here is how to
display
status text when someone hovers over the items in a menu strip or
toolstrip.
This handles one level of dropdowns; if you have more, you need to
use
recursion. Also, this only adds the events when the [tag] property is not
blank, and it displays the tag in the status strip.

You could enable tooltips on the menu items if you want tool tips. That's
an
entirely different thing from displaying info in the status strip.

To do this, you need to add handlers for each item for the MouseEnter
event
(to set the text) and the MouseLeave event (to blank it back out).

I am calling AddToolStripEventHandlers and AddMenuStripEventHandlers
in
my
Form_Load event. You could combine these.

Private Sub AddToolStripEventHandlers(ByVal tsToolStrip As ToolStrip)
For Each item As ToolStripItem In tsToolStrip.Items
If item.Tag IsNot Nothing Then
AddHandler item.MouseEnter, AddressOf MenuItem_MouseEnter
AddHandler item.MouseLeave, AddressOf MenuItem_MouseLeave
End If
Next
End Sub
Private Sub AddMenuStripEventHandlers(ByVal msMenuStrip As MenuStrip)
For Each item As ToolStripMenuItem In msMenuStrip.Items
If item.Tag IsNot Nothing Then
AddHandler item.MouseEnter, AddressOf MenuItem_MouseEnter
AddHandler item.MouseLeave, AddressOf MenuItem_MouseLeave
End If
'if you have dropdown menus inside your dropdown menus,
' you would probably want to make a recursive routine to
handle
that
If item.DropDownItems.Count > 0 Then
For i As Integer = 0 To item.DropDownItems.Count - 1
Dim ddItem As ToolStripItem
ddItem = item.DropDownItems(i)
If ddItem.Tag IsNot Nothing Then
AddHandler ddItem.MouseEnter, AddressOf
MenuItem_MouseEnter
AddHandler ddItem.MouseLeave, AddressOf
MenuItem_MouseLeave
End If
Next
End If
Next
End Sub

Private Sub MenuItem_MouseEnter(ByVal sender As Object, ByVal e
As
EventArgs)
If TypeOf sender Is ToolStripButton Then
Dim ctrl As ToolStripButton = DirectCast(sender,
ToolStripButton)
Me.ToolStripStatusLabel.Text = ctrl.Tag.ToString
ElseIf TypeOf sender Is ToolStripMenuItem Then
Dim ctrl As ToolStripMenuItem = DirectCast(sender,
ToolStripMenuItem)
Me.ToolStripStatusLabel.Text = ctrl.Tag.ToString
End If
End Sub

Private Sub MenuItem_MouseLeave(ByVal sender As Object, ByVal e
As
EventArgs)
Me.ToolStripStatusLabel.Text = String.Empty
End Sub

Robin
 
G

GS

Great! Thank you very much
RobinS said:
I got this is from PamelaFluente, and wanted to
post it as a response here in case you don't see
the other posting. The answer to your question
is below.
Thanks again to Pamela.
Robin S
-----------------------------------

Private Sub AddMenuStripEventHandlers(ByVal msMenuStrip As MenuStrip)
RecurseItems(Me.MenuStrip.Items)
End Sub

Sub RecurseItems(ByVal ToolStripItemCollection As ToolStripItemCollection)
Try
For Each ToolStripMenuItemChild As ToolStripMenuItem _
In ToolStripItemCollection
'Debug.Print("I am on " & ToolStripMenuItemChild.Text)
If ToolStripMenuItemChild.Tag IsNot Nothing Then
AddHandler ToolStripMenuItemChild.MouseEnter, _
AddressOf MenuItem_MouseEnter
AddHandler ToolStripMenuItemChild.MouseLeave, _
AddressOf MenuItem_MouseLeave
End If
RecurseItems(ToolStripMenuItemChild.DropDownItems)
Next ToolStripMenuItemChild
Catch ex As InvalidCastException
'ignore it; you'll get this for the separator lines
End Try
End Sub

---------------------------------

RobinS said:
I'm glad that worked for you, the tooltips I mean. I would
also like to know how to iterate all the down, and if I ever
figure it out, I'll post it here just for grins.

I thought I saw something in a MSFT article that said
something about using ReadNext to go through them, but
couldn't find it again, so maybe I dreamed it.

Like I said before, the only other thing I could think of
is if you could build the menu from scratch and add the
eventhandlers as you go. What a pain.

You could certainly read the menu info from a file and
create the menu from scratch, complete with the tooltips,
in different languages. Seems like that would be the
kind of thing you'd want to look into that CultureInfo
class for.

Good luck.
Robin S.

GS said:
Thank you. Now that I have fully converted to menuStrip with
ToolStripMenuItems and that I was finally find the tooltips, I am using
tooltips.

For now the tooltips is good

Nonetheless I would love to find out how to iterate through all the
items.
why> eventually I would want the menu text be from resource file for
multi-language interface.




You're right; I tried to figure out how to do it, but it's not
inherently obvious. I've searched all over, and can't find
anything that tells how to enumerate through all the items
in all the levels of a MenuStrip.

Why don't you use tooltips instead? If you enable the property
"Show Item Tooltips" for the Menu Strip, and then fill in the
tool tips for each option, they will be displayed when you hover
over the menu option.

The only other thing I can think of is to add the options to
the menustrip programmatically, and as you do that, add the
events.

Good Luck.
Robin S.


thank you.

I tired to deal with next level but failed as toolStripItem does not
have
dropdownItems, neither does menuStripItems.

I tried ctype but did not get to work either. all I need now is one
more
level for ToolStripMenuItems.


I sort of find a way to make the tag value appear in a status bar
but
it
is
far cry form automatic use of tag.


For each submenu time I have an event handler for select..

will be nice to add select event for submenu item in the instance
call
and
use the tag. but with the shallow knowledge that I have vb, I don't
have
a
clue yet.


any concrete suggestion?


I was able to set tooltips on objects other than main menu.
I would like to get the effect of tooltip or microhelp in the
bottom
status bar when the mouse is hovering over a submenu item.

How do I do that?
For example in outlook express, when one expand a main menu item
and
holds mouse over one of the enable sub menu item, one would see
some
sort
microhelp text in the status bar in the bottom



I'm not exactly sure if these are the same requests. Here is how to
display
status text when someone hovers over the items in a menu strip or
toolstrip.
This handles one level of dropdowns; if you have more, you need to
use
recursion. Also, this only adds the events when the [tag] property is
not
blank, and it displays the tag in the status strip.

You could enable tooltips on the menu items if you want tool tips.
That's
an
entirely different thing from displaying info in the status strip.

To do this, you need to add handlers for each item for the MouseEnter
event
(to set the text) and the MouseLeave event (to blank it back out).

I am calling AddToolStripEventHandlers and AddMenuStripEventHandlers
in
my
Form_Load event. You could combine these.

Private Sub AddToolStripEventHandlers(ByVal tsToolStrip As
ToolStrip)
For Each item As ToolStripItem In tsToolStrip.Items
If item.Tag IsNot Nothing Then
AddHandler item.MouseEnter, AddressOf
MenuItem_MouseEnter
AddHandler item.MouseLeave, AddressOf
MenuItem_MouseLeave
End If
Next
End Sub
Private Sub AddMenuStripEventHandlers(ByVal msMenuStrip As
MenuStrip)
For Each item As ToolStripMenuItem In msMenuStrip.Items
If item.Tag IsNot Nothing Then
AddHandler item.MouseEnter, AddressOf
MenuItem_MouseEnter
AddHandler item.MouseLeave, AddressOf
MenuItem_MouseLeave
End If
'if you have dropdown menus inside your dropdown menus,
' you would probably want to make a recursive routine to
handle
that
If item.DropDownItems.Count > 0 Then
For i As Integer = 0 To item.DropDownItems.Count - 1
Dim ddItem As ToolStripItem
ddItem = item.DropDownItems(i)
If ddItem.Tag IsNot Nothing Then
AddHandler ddItem.MouseEnter, AddressOf
MenuItem_MouseEnter
AddHandler ddItem.MouseLeave, AddressOf
MenuItem_MouseLeave
End If
Next
End If
Next
End Sub

Private Sub MenuItem_MouseEnter(ByVal sender As Object, ByVal e
As
EventArgs)
If TypeOf sender Is ToolStripButton Then
Dim ctrl As ToolStripButton = DirectCast(sender,
ToolStripButton)
Me.ToolStripStatusLabel.Text = ctrl.Tag.ToString
ElseIf TypeOf sender Is ToolStripMenuItem Then
Dim ctrl As ToolStripMenuItem = DirectCast(sender,
ToolStripMenuItem)
Me.ToolStripStatusLabel.Text = ctrl.Tag.ToString
End If
End Sub

Private Sub MenuItem_MouseLeave(ByVal sender As Object, ByVal e
As
EventArgs)
Me.ToolStripStatusLabel.Text = String.Empty
End Sub

Robin
 

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