Azerty560
Azerty560

Reputation: 125

How to detect a mouse click

As the title suggests, I am looking for a way to detect a mouse click. I'm not completely stupid, but I cannot use an event in this instance. Why? Because the function which uses it is in another class altogether. (And I have absolutely no idea how to put a subroutine in a class and an event, e, together)

So exactly how do you detect a mouse click within a sub? This is for windows programming. If you are looking for some code:

Public Class Ball
    Public Sub ResetBall() 
       MainForm.GFX.drawstring("Click to continue", Main.GameFont, Brushes.Orange, 300, 290) 
'Here! How do I detect a click here? D:
    End Sub
End Class

Thanks

EDIT: I found a possible solution to this:

    AwaitingClick = True
    Main.TmrMain.Stop()
    Main.TmrTime.Stop()

    Main.GFX.DrawString("Click to continue", Main.GameFont, Brushes.Orange, 300, 290)
    Main.Invalidate()
  'How do I stop the program from continuing? D:
    Main.TmrMain.Start()
    Main.TmrTime.Start()

Upvotes: 1

Views: 829

Answers (1)

Steven Doggart
Steven Doggart

Reputation: 43743

Is this a WinForm project? If so, you cannot "stop the program from continuing" until a mouse click occurs because the UI runs on a single thread. If you are keeping the UI thread busy, it will be unable to detect and process the click.

In any case, you need to get away from procedural programming techniques and start rethinking your design in an event-driven way. If you need to display a button or label and wait for it to be clicked before continuing, you need to simply display the button or label and then put the rest of the code in the click event handler for that control.

Upvotes: 4

Related Questions