mouse coordinates in MouseHover event? - vb.net

I know how to retrieve the mouse coordinate in a PictureBox.Click event though e
In a PictureBox.MouseHover, e does not return such information.
How do I get the mouse coordinates in a MouseHover event ? Is there a way ?
Thanks in advance.

Control.MouseHover "occurs when the mouse pointer rests on the control."
A typical use of MouseHover is to display a tool tip when the mouse pauses on a control within a specified area around the control (the "hover rectangle"). The pause required for this event to be raised is specified in milliseconds by the MouseHoverTime property.
So this event is not raised only whenever the mouse is over the control - there is a delay associated. So the position is somewhat irrelevant, as the mouse could have moved somewhat during that delay.
Do you really need to be using this event? As Dan-o mentioned, MouseMove passes a MouseEventArgs which does provide the coordinates, as you request. It may be the right option, depending on what exactly you're trying to do.
To get the mouse position at any time though, you can use the Cursor.Position property. This will give you the screen coordinates of the cursor. From here, you can call the Control.PointToClient method, to get the coordinates relative to a particular Control.

Related

How to click through elements?

I have two shape at same position, not same color, and when i click over them, i want to fire click event on both, not just the first.
These two shapes are in the same container.
I have tried getObjectsUnderPoint() under stage.on("mousemove"), but this function increase my FPS (60 to 32~, and inside there are just a console.log), So it's not a good solution.
I tried the bubble, the useCapture, but i think it isn't what i want.
I just want to fire click on all element behind my mouse.
If someone have a solution, please.
There are a few points here:
EaselJS objects sort of work like HTML DOM Elements. If an element has a mouse handler on it it will block objects in other hierarchies below it from receiving the event. This is just how it works. The main difference is that if you don't have mouse events, then they are just ignored (like if you set the pointerEvents on an HTML element to none to have the mouse ignore it).
Your idea with getObjectsUnderPoint is what I would have recommended. Running any hit-test logic on mousemove is going to be expensive (mousemove fires a LOT, which is why we give the ability to throttle the typical mouseover check if you enableMouseOver on the stage).
A few things to optimize it:
Ensure you are using mode=2 on your getObjectsUnderPoint, which will only check objects with mouse listeners. This greatly reduces the overhead in checking. [docs]
Instead of checking the stage on your own mousemove event, set a flag to check it on tick. This throttles it to your Ticker FPS at least. You could also set an interval to check it even less often. It can create a little bit of a visible lag, but you can probably find a nice balance.
Reduce what is checked. If you have a container with your clickable elements in it, you can only check that object for mouse interaction.
If your objects are the exact same, you can also just trigger the click manually on the second item.
obj1.on("click", function(event) {
obj2.dispatchEvent(event);
});
I hope those approaches provide you a solution. Let me know if you have follow-up questions.
Cheers,

How to listen active dragging event of an UWP UIElement?

How to track/listen active dragging event of UI Element in UWP. I added the flat CanDrag=true to enable the drag feature. Using the DragStarting and DragLeave can identify the start and end of drag. But want to get the X,Y coordinate of the UIElement on dragging. Any recommendation to achieve that? I dont want to use RenderTransform for this.
I don't think it's possible in standard Drag'n'Drop flow.
There're few options but they look like a crutch.
You may use manipulations and subscribe to Delta event. That's where RenderTransform comes in.
You may start some time loop and get visual position each frame. (The most crutchy idea)
Try to play wih IsHitTestVisible and subscribe to PointMove of some FrameworkElement behind.
Subscribe to PointEntered and PointExited to the elements you dragging over so they could fire events.
I prefer the first one. It's simple and it's plane.

VB.NET Mouse Hover Glitch?

So I'm working on this simple little program and I'm down to the aesthetics of it. Now, I've dabbled with VB since high school, so over 6 or so years, but I'm by no means a genius with it However, I know my way around quite well.
I have a mouse hover event set to make the alpha channel (or in this case, and soon to be changed, background color of the button) ever so slightly fade in to give a smoother effect, more metro, etc.
But the problem is with anything I do on that mouse hover event, there's about a 500 ms delay before that code initiates. Any thoughts?
I'm about 99% positive it's not the code inside the event as I've tried different code doing completely different things.
It's juts annoying, so thoughts? :)
Thank you!
The MouseHover event doesn't occur immediately. The events you're looking for are MouseEnter and MouseLeave.
Mouse events on controls occur in this particular order:
MouseEnter
MouseMove
MouseHover / MouseDown / MouseWheel
MouseUp
MouseLeave

allowing user to resize trackbar

i would like to allow the user to play around with the size of the trackbar in vb.net. is there an easy way to do this?
i want to clarify that i would like the user to be able to just resize the trackbar by dragging it just like in design mode.
You can assign a new size of the trackbar like this:
TrackBar1.Size = New Point(newwidth, newheight)
One way to handle the user interface you mentioned would be to use mousemove, mouseup, and mousedown events of the trackbar.
When you get a mousemove trackbar event with the left mouse button up, you could change the cursor depending on whether it's near an edge (left-right arrows for left or right edge, up-down arrows for top or bottom edge), near a corner (diagonal arrows), or elsewhere in the middle of the trackbar (4 arrows).
When you get a mousedown trackbar event, save the location. If it's near an edge or corner, you will be stretching the edge or the corner of the trackbar. If it's in the central area, you'll be moving it (if that's an option).
When you get a mousemove trackbar event with the left button down, move and/or resize the trackbar using the trackbar size and location properties. Compare the current location with the one you saved at the mousedown event, and stretch or move that distance. Perform the resize and/or relocate according to the current operation as defined by the location in the previous mousedown event (edge stretch, corner stretch, or move). You can either draw a rectangle or resize the trackbar at this point, whichever looks better to you.
When you get a mouseup event, finalize the operation by setting the new trackbar size and location.

How to implement mouse dragging in Visual Basic?

I need to create a quick-n-dirty knob control in Visual Basic 2005 Express, the value of which is incremented/decremented by "grabbing" it with the mouse and moving the cursor up/down. Because the knob itself doesn't move, I need to keep tracking the mouse movement outside of the rectangle of the control.
I use a Label with an ImageList to implement this (I have a list of 127 bitmaps representing the knob in various positions).
Which events should I react to?
You need the control to handle three events: Mouse Down, Mouse Move and Mouse Up. On the Mouse Down event, you will need to capture the mouse. This means the mouse messages are sent to the control that has the capture. In the mouse move event, if the input is captured then update the displayed image depending on the amount the mouse moved. In the mouse up event, release the capture if the input is captured.
The boolean jjnguy suggests is unnecessary as the Capture property of a Control is readable so it's possible to determine if the capture has been set.
Your problem will be to determine which bitmap you have to display based upon the coordinates the mouse reports in the mouse_move event. You'll need to perform some magic to transform the coordinates and come up with a value that you can use to pick the right image.
It doesn't sound too complicated, just a little bit of trial and error in the math. Skizz has already show you how to capture the events.