-1

So i want to make a maze game in Visual Basic and if the cursor reaches a certain panel, it will show a message box ONCE and then the Form closes.

The question is How? I've tried

Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
    If Cursor.Position = Panel1 Then
        MsgBox("Completed")
        Application.Exit()
    End If
End Sub

And didn't work. I got

Error 1 Overload resolution failed because no accessible '=' can be called with these arguments: 'Public Shared Operator =(left As System.Drawing.Point, right As System.Drawing.Point) As Boolean': Value of type 'System.Windows.Forms.Panel' cannot be converted to 'System.Drawing.Point'. C:\Documents and Settings\Admin\Local Settings\Application Data\Temporary Projects\WindowsApplication1\Form1.vb 4 12 WindowsApplication1

Remember that i want the message box to only appear once, because sometimes when the cursor is on the panel, it shows multiple msgbox until the cursor is outta there.

I want the mouse inside the panel and run a code.

Abhishek Agarwal
  • 1,190
  • 2
  • 19
  • 38

2 Answers2

0

I believe there is an event called 'mouse enter' event you can use so if you type the code for the messagebox in that even for the control you want them to mouseover it will pop up everytime they do that.

For it to to nly pop up once make a counter that adds 1 and dont execute that code if the counter is already on 1.

GamerGypps
  • 161
  • 13
0

I had a little search and found: Determine whether the mouse is over a control? (over a Control pixel range)

I just knocked up a test with a button and seemed to work fine. Please adapt to your own needs.

Private Sub Button1_Paint(sender As Object, e As PaintEventArgs) Handles Button1.Paint
    Debug.WriteLine(MouseIsOverControl(Button1))
End Sub

Public Function MouseIsOverControl(ByVal c As Control) As Boolean
    Return c.ClientRectangle.Contains(c.PointToClient(Control.MousePosition))
End Function

In this example I've just output "true or false" to determine detection. You can test and change it to your own needs to determine what you want to do depending on 'true/false'. Hope this helps.

video.baba
  • 817
  • 2
  • 6
  • 11