Mouse over: Border, else not!

Posted on 2004-10-23
Last Modified: 2010-04-23

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

Question by:Dumdidum
    1 Comment
    LVL 11

    Accepted Solution

    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.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Shellfire Box VPN + Lifetime Subscription

    The Shellfire Box easily connects all of your devices, even those that don't offer the possibility to establish a safe vpn connection. Access blocked content and surf safely, no matter where in the world you are located.

    This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
    The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (…
    With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
    This video Micro Tutorial is the first in a two-part series that shows how to create and use custom scanning profiles in Nuance's PaperPort 14.5 ( But the ability to create custom scanning profiles al…

    913 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now