How to catch MouseOver while the mouse is captured by another control - c#

I have some user controls on a wpf form. I have set a trigger for them on IsMouseOverProperty so that every time the mouse is over any of them, the Background color get changed. I also have a trigger of IsPressedProperty so that every time that the user press the mouse button, the Background color get changed to another color.
Furthermore on the OnMouseLeftButtonDown event I set this. CaptureMouse() and in the OnPreviewMouseLeftButtonUp event I set this.ReleaseMouseCapture() so that when the user clicks anywhere else on the window, the the UserControl lost its mouse capture.
Every thing seems good so far unless when I press the mouse button on a user control and I move the mouse over the other user controls, their Background color never get changed because the mouse is captured by the control on which the mouse is captured.
Now I need to know is there any way to capture mouse on a user control and still be able to find if the mouse is over other controls?

Related

How turn on auto update content on mouse button scrolling? wpf

I use ScrollViewer. When I scroll the page with the mouse wheel, everything works fine and the ScrollChanged event cause after each scroll. But when I scroll through the contents of the panel by pressing and holding the scroll bar, then ScrollChanged cause only when I release the mouse button. How can I fix this and make it always update the content.
From Pro WPF 4.5 in C#:
Finally, the ButtonBase class adds a ClickMode property, which determines when a button fires its Click event in response to mouse actions. The default value is ClickMode.Release, which means the Click event fires when the mouse is clicked and released. However, you can also choose to fire the Click event when the mouse button is first pressed (ClickMode.Press) or, oddly enough, whenever the mouse moves over the button and pauses there (ClickMode.Hover).

scroll between grid buttons using mouse wheel in UWP

I have a UWP app in which I have several buttons. Once the app starts to run, I set the focus in my code to the first button using a code like this:
firstButton.Focus(FocusState.Programmatic);
After this point, what I am interested in is that once the user use the mouse wheel, the UWP app automatically scroll to second, third, fourth, ... button(exactly like when we use tab key on keyboard to move between buttons).
However, when I use mouse wheel, nothing happens in the app.
I should also say that in firstbutton xaml, I use pointerwheelchanged event listener to change the focus to second button. However, this event handler does not work with mouse wheel UNTIL I MOVE THE MOUSE CURSOR INSIDE THE AREA OF FIRST BUTTON. What I am interested in is that this scrolling using mouse wheel becomes automatic exactly like the tab key of keyboard.
Any suggestions?
Place the event on the container control (like the Grid). If it's a control that already processes the event, use the AddHandler method with handledEventsToo set to true.

WPF: Keep custom cursor while mouse is down

I have created a custom cursor and applied it to my control via the Cursor property and it displays correctly while the mouse is over the control, however once I click, the cursor changes back to default. What I would like is the custom cursor to be persisted while the mouse is down (and potentially being moved) and return to normal whenever the mouse comes up (over any possible control). I realize I could do this by setting the Mouse.OverrideCursor on mouse down, but I'm not sure how I would set the override cursor back when the mouse comes up because it could be released anywhere on the screen. The behavior I want is similar to clicking in a cell and dragging in Excel. Does anyone have any suggestions for how I can implement this behavior?
Edit:
I tried following the advice in this answer: https://stackoverflow.com/a/2986757/3818295 however my PreviewMouseLeftButtonUp handler never gets invoked.
If you want to change the cursor globally for your entire application, then use the Mouse.SetCursor method. The cursor will remain changed until you explicitly change it again. To change it back, call Mouse.SetCursor(Cursors.Arrow); don't pass in null or Cursors.None, as those will give you a special 'invisible' cursor.
If you want to change the cursor only while the mouse is down, then the control that initiated the 'drag' operation will need to capture the mouse so that it continues to receive events even after the cursor leaves the original control. This ensures the source control eventually receives the mouse up event (unless the capture is lost). To capture the mouse, call either c.CaptureMouse() or Mouse.Capture(c), where c is your control. You will need to release the capture when the drag operation terminates, e.g., via c.ReleaseCapture().
It would be a good idea to temporarily subscribe to the drag source's LostMouseCapture event for the duration of the drag, and cancel the drag operation if capture is lost. If capture is lost, you aren't guaranteed to receive the mouse up event, so at that point you should just give up. Remember to unsubscribe from LostMouseCapture after the drag terminates.

Display tooltip when mouse movement stop

I have a grid-view with merged cells and rows which look like this.
I am using grid view mouse enter cell and mouse leave cell events to call the tool-tip show and hide methods.
Problem I am having is, since the cells are very closer tooltip get displayed when I moving across the grid. What I am trying to achieve is display the tooltip only when mouse is stop moving.
Is it possible to capture current state of mouse where I can capture mouse is moving or not.
I have looked at the Control.MouseMove Event, but can I find the current state of the mouse using that.
Update
I did try something like this
In MouseMove event of the gridview tooltip.Hide()
In
MouseHoverCell tooltip.Show() but had no luck with it
Thanks
What you need here is to leverage the OnMouseHover and OnMouseMove events.
The OnMouseHover event is fired when the mouse stops moving. So, in your case, you can fire this event when the mouse stops, pick up the containing cell and show your tooltip. When the OnMouseMove event fires teardown the tooltip and start again.
I hope this helps.

Mouse middle button click functionality in Infragistics Ultragrid

In Excel, middle mouse button click work as a toggle. That is, if you press it once, it will allow you to scroll in your chosen direction till the time you click it again.
However, in Infragistics Ultragrid, this scrolling functionality is available only while middle mouse button remains pressed. How can I make Infragistics Ultragrid middle mouse button click work as in excel?
Otherwise also, what is the way to do it in winforms?
It's not as complicated as you might think. Clicking either the mouse wheel or middle button (depending on the type of Mouse the user has) fires off a MouseWheel event which must be handled and processed like any other event.
You'll need to configure a small "scrolling state machine" for you application. By this, I mean that the user is either scrolling in, say, a NormalMode, where using scroll bars or flicking up/down on the mouse wheel produces the same effect (scrolling up/down). Or, the application is in a HoverScrollingMode which occurs whenever the user has clicked the middle button (or mouse wheel) and is moving the mouse north or south of the click point.
I can't give you a programming example without seeing how your application currently handles other types of mouse events, but your overall strategy is to handle these MouseWheel events, use them to switch your application state (into, say, HoverScrollingMode) and then programmatically move the viewport up/down depending on the current position of their mouse.
Hope this helps, and good luck!

Categories