Help with MouseOver

What is the code for the MouseOver event ie
Private Sub Label1_MouseOver(???????????)
I want the label to know when the mouse is over it so it can grow or shrink or change colors while the mouse is still over it. Then I want the label to know when the mouse is off of it so it will go back to normal. I know how to do Private Sub Label1_MouseMove but that isn't really what I need. I need it to call an event as soon as the mouse is over the label and keep going until the mouse isn't on it anymore reguardless of whether the mouse is moving or not while it is on the lable. Thank you.

Comments

  • : What is the code for the MouseOver event ie
    : Private Sub Label1_MouseOver(???????????)
    : I want the label to know when the mouse is over it so it can grow or shrink or change colors while the mouse is still over it. Then I want the label to know when the mouse is off of it so it will go back to normal. I know how to do Private Sub Label1_MouseMove but that isn't really what I need. I need it to call an event as soon as the mouse is over the label and keep going until the mouse isn't on it anymore reguardless of whether the mouse is moving or not while it is on the lable. Thank you.
    :


    There is no mouse-over event in VB6 at least.
    Just respond to the mouse-move events of the
    label and all adjacent controls, including the
    form. I'd use a flag to keep track of the
    label's state and bypass the state-altering
    code instead of changing it with every single
    motion of the mouse.

  • If you want to get tricky you could try subclassing your label to catch the WM_MOUSEMOVE event, but be forewarned, subclassing in VB introduces a whole new set of issues.
  • [code]
    Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    'insert code here
    End Sub
    [/code]

    keep it simple :P
    [red]ph[/red][blue][/blue][red]t[/red]
    [red]http://fade.to/phet[/red]
    [blue]12d.hypermart.net[/blue]
    [red][email protected][/red]

  • : [code]
    : Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    : 'insert code here
    : End Sub
    : [/code]
    :
    : keep it simple :P
    : [red]ph[/red][blue][/blue][red]t[/red]
    : [red]http://fade.to/phet[/red]
    : [blue]12d.hypermart.net[/blue]
    : [red][email protected][/red]
    :
    :

    He's after mousein and mouseout notification. Mousein can be hacked using mousemove, but trying that for mouseout is flaky.
  • : What is the code for the MouseOver event ie

    When you get a MouseMove event, start a Timer. Every time the Timer fires, use the GetCursorPos and ScreenToClient API functions to see if the mouse is still over the control. If it is, do whatever you want to do. If the mouse is no longer over the control, disable the Timer.

    This example may help:

    http://www.vb-helper.com/HowTo/hlitctl.zip



  • This little hack works fine. Use the mouseMove events for both the Label and Form. When the mouse enters the Label that mouseMove is triggered. When the mouse leaves the Label the Forms mouseMove is triggered. The just toggle a global var to keep track of the state.

    Dim mouseIsOver

    Private Sub Form_Load()
    mouseIsOver = False
    End Sub

    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If mouseIsOver Then
    ' The mouse just left the label, do something
    mouseIsOver = False
    End If
    End Sub

    Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Not mouseIsOver Then
    ' The mouse just entered the label, do something
    mouseIsOver = True
    End If
    End Sub

  • : Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    : If mouseIsOver Then
    : ' The mouse just left the label, do something
    : mouseIsOver = False
    : End If
    : End Sub
    :
    : Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    : If Not mouseIsOver Then
    : ' The mouse just entered the label, do something
    : mouseIsOver = True
    : End If
    : End Sub

    That sort of works. It has problems if (1) there are other controls on the form so they get the MouseMove events instead of the form, or (2) the user moves the mouse very quickly off the form so no MouseMove events on the form fire.




  • That's true.
    As I said it was a hack not a fool-proof solution. For fool-proof you would have to use coordinate-checking I guess.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories