B
Brian Henry
I thought this was useful, its a extender i just wrote for the new .NET menu
strip and status strip to extend the menu items to add a status message so
when a mouse rolls over the item it displays the text on the status strip
lable specified for the extender.. all you have to do is copy this to a code
file, and add it as a control to your form. set the status lable property of
the extender control then set the status mesages of the menu items and run
it and watch it do its thing
Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
<ProvideProperty("StatusMessage", GetType(Component))> _
Public Class StatusMessage
Inherits Component
Implements IExtenderProvider
Dim ht_ControlLookup As Hashtable = New Hashtable
Dim s_LastMessage As String = String.Empty
Public Sub SetStatusMessage(ByVal senderComponent As Component, ByVal
strMessage As String)
If Not ht_ControlLookup.Contains(senderComponent) Then
ht_ControlLookup.Add(senderComponent, strMessage)
Dim pMenuItem As ToolStripMenuItem = CType(senderComponent,
ToolStripMenuItem)
If pMenuItem IsNot Nothing Then
AddHandler pMenuItem.MouseMove, AddressOf Handle_MenuSelect
AddHandler pMenuItem.MouseLeave, AddressOf Handle_MenuLeave
AddHandler pMenuItem.MouseEnter, AddressOf Handle_MenuEnter
Else
ht_ControlLookup(senderComponent) = strMessage
End If
End If
End Sub
Public Function GetStatusMessage(ByVal senderComponent As Component) As
String
If ht_ControlLookup.Contains(senderComponent) Then
Return ht_ControlLookup(senderComponent).ToString
End If
Return String.Empty
End Function
Public Function CanExtend(ByVal senderComponent As Object) As Boolean
Implements System.ComponentModel.IExtenderProvider.CanExtend
Return TypeOf senderComponent Is ToolStripMenuItem
End Function
Private m_StatusBar As ToolStripStatusLabel
Public Property StatusBar() As ToolStripStatusLabel
Get
Return m_StatusBar
End Get
Set(ByVal value As ToolStripStatusLabel)
m_StatusBar = value
End Set
End Property
Private Sub Handle_MenuSelect(ByVal pControl As Object, ByVal e As
MouseEventArgs)
If StatusBar Is Nothing Then
Exit Sub
End If
If ht_ControlLookup.Contains(pControl) Then
If Not ht_ControlLookup(pControl).ToString.Trim = String.Empty Then
StatusBar.Text = ht_ControlLookup(pControl).ToString
End If
End If
End Sub
Private Sub Handle_MenuLeave(ByVal pControl As Object, ByVal e As EventArgs)
If StatusBar Is Nothing Then
Exit Sub
End If
StatusBar.Text = Me.s_LastMessage
End Sub
Private Sub Handle_MenuEnter(ByVal pControl As Object, ByVal e As EventArgs)
If StatusBar Is Nothing Then
Exit Sub
End If
Me.s_LastMessage = StatusBar.Text
End Sub
End Class
strip and status strip to extend the menu items to add a status message so
when a mouse rolls over the item it displays the text on the status strip
lable specified for the extender.. all you have to do is copy this to a code
file, and add it as a control to your form. set the status lable property of
the extender control then set the status mesages of the menu items and run
it and watch it do its thing
Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
<ProvideProperty("StatusMessage", GetType(Component))> _
Public Class StatusMessage
Inherits Component
Implements IExtenderProvider
Dim ht_ControlLookup As Hashtable = New Hashtable
Dim s_LastMessage As String = String.Empty
Public Sub SetStatusMessage(ByVal senderComponent As Component, ByVal
strMessage As String)
If Not ht_ControlLookup.Contains(senderComponent) Then
ht_ControlLookup.Add(senderComponent, strMessage)
Dim pMenuItem As ToolStripMenuItem = CType(senderComponent,
ToolStripMenuItem)
If pMenuItem IsNot Nothing Then
AddHandler pMenuItem.MouseMove, AddressOf Handle_MenuSelect
AddHandler pMenuItem.MouseLeave, AddressOf Handle_MenuLeave
AddHandler pMenuItem.MouseEnter, AddressOf Handle_MenuEnter
Else
ht_ControlLookup(senderComponent) = strMessage
End If
End If
End Sub
Public Function GetStatusMessage(ByVal senderComponent As Component) As
String
If ht_ControlLookup.Contains(senderComponent) Then
Return ht_ControlLookup(senderComponent).ToString
End If
Return String.Empty
End Function
Public Function CanExtend(ByVal senderComponent As Object) As Boolean
Implements System.ComponentModel.IExtenderProvider.CanExtend
Return TypeOf senderComponent Is ToolStripMenuItem
End Function
Private m_StatusBar As ToolStripStatusLabel
Public Property StatusBar() As ToolStripStatusLabel
Get
Return m_StatusBar
End Get
Set(ByVal value As ToolStripStatusLabel)
m_StatusBar = value
End Set
End Property
Private Sub Handle_MenuSelect(ByVal pControl As Object, ByVal e As
MouseEventArgs)
If StatusBar Is Nothing Then
Exit Sub
End If
If ht_ControlLookup.Contains(pControl) Then
If Not ht_ControlLookup(pControl).ToString.Trim = String.Empty Then
StatusBar.Text = ht_ControlLookup(pControl).ToString
End If
End If
End Sub
Private Sub Handle_MenuLeave(ByVal pControl As Object, ByVal e As EventArgs)
If StatusBar Is Nothing Then
Exit Sub
End If
StatusBar.Text = Me.s_LastMessage
End Sub
Private Sub Handle_MenuEnter(ByVal pControl As Object, ByVal e As EventArgs)
If StatusBar Is Nothing Then
Exit Sub
End If
Me.s_LastMessage = StatusBar.Text
End Sub
End Class