VB.Net - Toolstrip Button Mousehover Event

1.7k views Asked by At

Is there a way to change the size of the toolstrip button on mousehover event?
I tried this but didn't work.

Private Sub tsDriver_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles tsDriver.MouseHover
    Dim pt As Point
    pt.X = 60
    pt.Y = 70
    tsDriver.Size = pt

End Sub

I'd like to have the effect like, when mouse is hovered on the button, it will grow big and when the mouse leaves it will go back to its original size.

2

There are 2 answers

5
Nadeem_MK On

You should instantiate a the size, which is a separate object.Try this, it should work;

Private Sub tsDriver_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles tsDriver.MouseHover

    Dim pt As New System.Drawing.Point 
    pt.X = 60
    pt.Y = 70
    tsDriver.Size = New System.Drawing.Size(pt)

End Sub

Note that the MouseHover event only triggers when the mouse cursor enters the control location.
So, for the button to shrink to original size, the MouseLeave event should be coded;

Private Sub tsDriver_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles tsDriver.MouseLeave

    Dim pt As New System.Drawing.Point 
    pt.X = 40  ' Original size
    pt.Y = 50
    tsDriver.Size = New System.Drawing.Size(pt)
End Sub
0
Malcolm Salvador On

Should only the button resize? or would it be okay for the rest of the buttons resize as well??

If so, you can Manipulate the ImageScalingSize property of the tool tip window

       Dim pt2 As Point
       pt2.X = 100
       pt2.Y = 100

       ToolStrip1.ImageScalingSize = pt2

This assumes it's okay for the rest of the buttons to grow as well.