Mouse over: Border, else not!

Hi

I have a label and now I want to do this:

If I move the mouse over the label, the border around the label should appear, if I move away from the label the border should disappear

It's clear to use the mouse_enter and mouse_leave-property and that is working correctly but the problem is the following:

If I activate the border, the text in the label will move one pixel to right and to the bottom. To equilaze that I have used:

    Private Sub Label1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Label1.MouseEnter
        Label1.Top = Label1.Top - 1
        Label1.Left = Label1.Left - 1
        Label1.BorderStyle = BorderStyle.FixedSingle
    End Sub

    Private Sub Label1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Label1.MouseLeave
        Label1.Top = Label1.Top + 1
        Label1.Left = Label1.Left + 1
        Label1.BorderStyle = BorderStyle.None
    End Sub

But that's not working correctly. It is activating the border but if I leave the label with the mouse on the botton or right border the border is not disappearing...

How can I solve that?

Thanks a lot

Sven
DumdidumAsked:
Who is Participating?
 
Gregory MillerConnect With a Mentor General ManagerCommented:
Draw the label using the default form background color and leave the border drawn at all times. The MouseEnter and MouseLeave events should simply change the color of the border. This will prevent the need to compensate for the movement of the text and should simplify the border display on and off visual effect you are looking for.

-greg
0
All Courses

From novice to tech pro — start learning today.