Mouse middle button click functionality in Infragistics Ultragrid - c#

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!

Related

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.

Controlling Microsoft Charting Controls focus

I am currently using MSCharts in one of my windows forms. One of the quirky things about MSCharts is that you cannot trigger a MouseWheel event in the chart unless the chart has focus. To combat this, most people are saying that one should add a MouseEnter event to the chart and then Focus() the chart to allow one's MouseWheel events to fire (see here: Enabling mouse wheel zooming in a Microsoft Chart Control).
Let's say that I pull up a completely different window (call it Window A) that just so happens to be partially in front of my chart (call it window is Window B). If I accidentally move the mouse over the chart in Window B for even 10 milliseconds, Window B will take focus and Window A will be placed behind it, which is incredibly frustrating.
I've explored different options.
Setting Window B's TopMost property to true. The problem with this is that the user has to either close the window or minimize it to hide it. If there are a lot of windows up, it seems to be just as frustrating as the initial issue.
Instead of giving the MouseEnter event the ability to Focus(), let the MouseClick or MouseHover event to Focus(). The problem with MouseClick is that the user will always have to click on the chart first to zoom, which isn't bad, but can be annoying. MouseHover is okay, but the time that the event considers to be a hover is really short.
In the end, I want it so that I can put my mouse over the chart and scroll in without having to do anything (mouse clicks, or anything else). In addition to this, I don't want the form that contains the chart to jack the focus back to it if I accidentally move my mouse over it for just a second.
EDIT:
It seems that according to #TaW, the chart doesn't need focus to trigger MouseWheel events in Window 10. This is not the case in Windows 7, unfortunately.
This may seem slightly hacky, but it works in this case:
This works through the use of the FindForm method. I never knew it was a thing until now. You can read more about it here: https://msdn.microsoft.com/en-us/library/system.windows.forms.control.findform(v=vs.110).aspx
myChart.MouseEnter+= delegate(object sender, EventArgs args) //add a mouse enter event to your chart
{
if (!chart.Focused) //if chart isn't focused
{
if (chart.FindForm().ContainsFocus) //check if the form the chart is in contains focus
chart.Focus(); //if the chart isn't focused, but the form is focused, focus on the chart
}
};
This will still give the chart focus when you move your mouse into it and it will not allow the form that contains the chart to jack the focus from the form you're in.

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

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?

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.

How can I move the TrackBar in response to mouse events in C#?

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.

Categories