changeable ToolTip for Control without MouseMove-event

  • Thread starter Thread starter DraguVaso
  • Start date Start date
D

DraguVaso

Hi,

I have a Control from another company that I have to put in my application.
That control has 7 buttons, and I want to change the ToolTip according to
the button above the mouse is moving.

I could do this by calculating myself the position of the MouseCursor and
knowing like that wich ToolTip I have to use. But one big problem: the
Control doesn't have a MouseMove-event or something like that.

So now my question: How do I add a MouseMove-event to a control? Or is there
another solution for my problem?

Thanks a lot in advance!

Pieter
 
Hi,


You can use the nativewindow class to recieve the windows messages
for control. You will recieve the wm_mousemove message when the mouse is
moving over the control.


Sample class

Private Class MyListener

Inherits NativeWindow

Public Event MyMouseMove(ByVal sender As Object, ByVal e As EventArgs)



Const WM_MOUSEMOVE = &H200



Private ctrl As Control

Public Sub New(ByVal ctrl As Control)

AssignHandle(ctrl.Handle)

End Sub

Protected Overrides Sub WndProc(ByRef m As Message)

' Listen for operating system messages



If m.Msg = WM_MOUSEMOVE Then

RaiseEvent MyMouseMove(ctrl, New EventArgs)

End If

MyBase.WndProc(m)

End Sub

Protected Overrides Sub Finalize()

ReleaseHandle()

MyBase.Finalize()

End Sub

End Class



How to use

Dim WithEvents sl As MyListener

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

sl = New MyListener(TextBox1)

End Sub



Private Sub sl_MyMouseMove(ByVal sender As Object, ByVal e As
System.EventArgs) Handles sl.MyMouseMove

Me.Text = "My Mouse Move"

End Sub



Ken
 
Thanks a lot!!

Ken Tucker said:
Hi,


You can use the nativewindow class to recieve the windows messages
for control. You will recieve the wm_mousemove message when the mouse is
moving over the control.


Sample class

Private Class MyListener

Inherits NativeWindow

Public Event MyMouseMove(ByVal sender As Object, ByVal e As EventArgs)



Const WM_MOUSEMOVE = &H200



Private ctrl As Control

Public Sub New(ByVal ctrl As Control)

AssignHandle(ctrl.Handle)

End Sub

Protected Overrides Sub WndProc(ByRef m As Message)

' Listen for operating system messages



If m.Msg = WM_MOUSEMOVE Then

RaiseEvent MyMouseMove(ctrl, New EventArgs)

End If

MyBase.WndProc(m)

End Sub

Protected Overrides Sub Finalize()

ReleaseHandle()

MyBase.Finalize()

End Sub

End Class



How to use

Dim WithEvents sl As MyListener

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

sl = New MyListener(TextBox1)

End Sub



Private Sub sl_MyMouseMove(ByVal sender As Object, ByVal e As
System.EventArgs) Handles sl.MyMouseMove

Me.Text = "My Mouse Move"

End Sub



Ken
 
Back
Top