RubberDuckDebugging
RubberDuckDebugging

Reputation: 59

Mouse cursor over a picture box. Visual Basic

I have an exam coming up in Visual Basic so I'm trying to bite through the tasks given in lessons.

What I have to do, basically, is create a form with pictureboxes on top of it and every time the mouse goes on top of the picture box it adds +1 to a counter and while on top of the picture, it adds to a time counter.

I can grasp how to manage the counters but have no idea how to do the mousecontrol. Is there a function for that and if there is how exactly does it execute in the given situation.

I did find this:

but unsure whether it's the function I should be using.

Upvotes: 1

Views: 1733

Answers (1)

har07
har07

Reputation: 89325

You can listen to MouseEnter event of PictureBox. That event will raised whenever the mouse goes on top of the picture box, exactly as you want. And you may also want to listen to MouseLeave event, to stop the time counter when the mouse leave from top of picture box.

UPDATE : some more explanation as per request

Register an event handler to handle MouseEnter event. Refer to this link if you're not sure how. In the MouseEnter event handler sub, you can put your logic to modify counter and starting a timer (if I don't misunderstood the "time counter" you mentioned).

Then register another event handler to handle MouseLeave event. In this handler, you put codes to stop that timer I mentioned above.

Upvotes: 2

Related Questions