Toolbar button being hovered over

  • Thread starter Thread starter Brian Henry
  • Start date Start date
B

Brian Henry

How do you figure out which toolbar button is being hovered over so you can
show related text on the status bar? I don't want to use a tooltip. Thanks!
 
Hi Brian,

I made a sample for you, check if it fits your needs?

Cor

\\\needs two buttons and a label on a form
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim btnArea As Button() = New Button() {Button1, Button2}
For Each btn As Button In btnArea
AddHandler btn.MouseLeave, AddressOf Button_MouseLeave
AddHandler btn.MouseEnter, AddressOf Button_MouseEnter
Next
End Sub
Private Sub Button_MouseLeave(ByVal sender As Object, _
ByVal e As System.EventArgs)
DirectCast(sender, Button).BackColor = Color.Black
Me.Label1.Text = ""
End Sub
Private Sub Button_MouseEnter(ByVal sender As Object, _
ByVal e As System.EventArgs)
DirectCast(sender, Button).BackColor = Color.Red
Me.Label1.Text = DirectCast(sender, Button).Name
End Sub
End Class
///
 
* "Brian Henry said:
How do you figure out which toolbar button is being hovered over so you can
show related text on the status bar? I don't want to use a tooltip. Thanks!

Quick and Dirty:

\\\
Private Sub ToolBar1_MouseMove( _
ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs _
) Handles ToolBar1.MouseMove
Dim b As ToolBarButton
For Each b In Me.ToolBar1.Buttons
If b.Rectangle.Contains(New Point(e.X, e.Y)) Then
Me.Text = b.ToolTipText
Return
End If
Next b
End Sub
///
 
Hi Herfried,

Nice

But I assume processor consuming. I did not read "toolbarbutton" but
"toolbar button".

I took it in my snippets, and changed this because that tooltip is a little
bit useles (with the text by HKW(full) a little bit optimized by Cor
\\\\
For Each b In Me.ToolBar1.Buttons
If b.Rectangle.Contains(New Point(e.X, e.Y)) Then
Select Case b.Text
Case "1" 'the text from the button
Me.Label1.Text = "Button 1 is hovered"
Case "2"
Me.Label1.Text = "Button 2 is hovered"
Case Else
Me.Label1.Text = ""
End Select
End If
Next
///
:-)

Cor
 
Back
Top