[.NET] Form Mouse Enter/Exit

Soldato
Joined
12 Jun 2005
Posts
5,361
Hi there,

I want to create something so that if my mouse enters anywhere that is within the forms boundaries even if its onto an object which is on the form, and then something for when it leaves the boundaries.

Is this possible?

Thanks.
 
I have fixed this, and just to say the code above is incorrect. Because if i go onto an object, the event doesn't trigger, it has to go onto the form for that to trigger.
 
happytechie said:
the phrase you were looking for was thanks for your help but that wasn't quite the code I needed...

Chillax mate, thats what i meant, doesn't do what i stated in the opening thread, I wasn't taking a digg.
 
Hi there,

Well the solution i used was something like this:

Code:
'A rectangle that covers the whole form
Dim formRectangle As New Rectangle(0, 0, 190, 70)

'A Timer to check if the mouse is on the form
    Private Sub mouseOnForm(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles onForm.Tick

'If the rectangle contains the mouse coordinates of where the mouse is
        If formRectangle.Contains(Me.PointToClient(System.Windows.Forms.Cursor.Position)) Then
            'If it does then do this
            rectangleMove.Location = New Drawing.Point(173, 2)
            Me.Opacity = 0.8
        Else
            'If it doesn't then do this.
            rectangleMove.Location = New Drawing.Point(-20, -20)
        End If
        Me.Refresh()

    End Sub

And you just have the timer running when you need to check if the mouse is on the form.

The reason I needed this, and if you refer to my program in the "Little MP3 Player" thread. When the mouse is anywhere on the form a rectangle appears (rectangleMove). When you click and drag on that rectangle it moves the form where you drag the form.

Hope that helps.
 
Back
Top Bottom