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).
Related
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.
I have a form with the panel, which will have some checkboxes for options. I made panel slide in to the form when mouse hovers the edge of it (edge of panel). I made it hide (slide back) when mouse leaves the panel. The problem is that when I point a checkbox in this panel a mouseleave event occures and panel slides back so I cannot check checkbox. Is there any way to prevent mouseleave event when mouse is still over the panel and some checkboxes in it? My idea for know is to make a condition based on mouse pointer position in mouseleave event, but I hope that there is a way to make app treat a checkbox as a part of panel. Did not put any food since it is not problem of it. But can post if needed.
What happens here is that the mouseleave event of the checkbox triggers mouseleave event of the panel due to the event bubbling. You can read more about event bubbling here.
To prevent the event bubbling, attach mouseleave event on the checkboxes and call event.stopPropagation().
Sample code with jQuery:
$("checkboxes_selector").on("mouseleave", function(event){
event.stopPropagation();
});
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.
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!
This is probably a n00b query. I have a need where I want to change the trackbar value based on a mouse down event. This I achieved as follows:
private void MoveTrackBarToMouseClickLocation(TrackBar a_tBar, int a_mouseX)
{
// Jump to the clicked location
double dblValue;
dblValue = ((double)a_mouseX / (double)a_tBar.Width) * (a_tBar.Maximum - a_tBar.Minimum);
a_tBar.Value = Convert.ToInt32(dblValue);
}
That part works fine. I am having trouble getting the scroll working while the mouse button is pressed. e.g. If I click on the trackbar and it takes me to say value 50 with the mouse down, I want to be able to scroll right or left (from value=50) while that mouse is down.
I hope I have made my small issue clear.
Any help is appreciated.
Thanks
You need to execute your code in the MouseMove event, as well as the MouseDown event.
This event occurs when the mouse is moved while one of the buttons is held down. In contrast, the MouseDown event that you currently handle only gets raised once each time the mouse button is pressed down. That's why the TrackBar is not moving when the user moves the mouse, but is working properly the first time the button is pressed.
You didn't show the code where you wired up the event handlers and/or call the MoveTrackBarToMouseClickLocation function, so that's as specific as I can get. But if you managed to wire up the MouseDown event already, this should be a simple fix.