June 26th, 2012, 01:56 AM
Trouble with the mouse_enter event
Hello, I'm trying to make a minesweeper program. I'm mostly finished, but now I'm trying to add the little details.
So you know how in minesweeper when you hold down your mouse button and move it around, the block that it's in presses down, and when you move it out of that block it pops back up?
I have it now so that if the user presses the mouse button inside of a box then it presses down, and if they move the cursor outside of the box and then release the mouse then it pops back up.
My problem is this: I can't get it so that when I enter a new box without releasing the mouse button, that box goes down.
My method right now is to get an "If" statement in the Mouse_enter and Mouse_leave events for each box that checks whether the mouse is held down or not using a Boolean.
But it isn't working because when the mouse enters the box with the button held down from a different box, it doesn't do anything. It only performs the code if the button isn't held down.
I was wondering if anyone knows why this is that it doesn't perform the code if the button is held down already? Or, is there an easier way to do this? Thank you in advance.
I apologize if the way I worded this is confusing. My thoughts are pretty jumbled. If you need clarification about anything, please ask.
June 26th, 2012, 12:50 PM
I am not sure what you are using, but with VB6 the "MouseMove" event is what you would use. As the mouse is moved over an object, the event is triggered and code can be attached to it.
June 26th, 2012, 03:09 PM
Thank you for replying, but my problem is still happening when I use mouse_move instead. I'm running visual studio 2010.
It doesn't work because when the mouse presses down on another block, and then drags outside of that block and moves over the new block without letting go of the mouse button, for some reason it doesn't activate that mouse_move code in the new block.
I think maybe it's not registering because it's still trying to do something with the original block as long as the mouse is held down? It seems like maybe this is a just a problem with the way I'm trying to do it. Is there possibly some way that i should implement a drag/drop instead?
June 27th, 2012, 01:42 AM
I assumed that you wanted to execute code as the mouse moved over an object, not with the mouse depressed. When you click the mouse, it initiates an action with the object it is currently pointing to. Other than Drag & Drop, you cannot carry that action elsewhere. When the mouse is released, the action is still carried out on the object it was originally pointing to. This behaviour has nothing to do with the programming language; it is a property of the operating system itself.