How can I make a WinForms ListView scroll vertical by MouseWheel?
I'm using C#.
Is it OK if the list scrolls only when it has focus? If so, use the Control.MouseWheel event.
Do you want the list to scroll if it doesn't have focus? Then you need to need to either implement a mouse hook, as described in the other article, or take a look at the Application.AddMessageFilter method. Application.AddMessageFilter gives you a managed version of a mouse hook. You get to preview the messages as they come in. I wrote something about it here.
Related
I have a System.Windows.Forms.VScrollBar control on my form and select it programmatically by calling scrollBar.Select() so that mouse-wheel and keyboard scrolling just works (without the user having to explicitly select the scrollbar beforehand). However, this causes the scrollbar cursor to constantly flash every half a second or so. Is there any way to stop this behaviour? I have looked around but I can't find any property to control this behaviour?
I even tried creating a custom scrollbar inherting from VScrollBar and overriding OnPaint, but that's not even getting called, so I guess its not used by VScrollBar at all.
I don't know that keyboard scrolling can be easily implemented on a WinForms AutoScroll control (see this answer). I do know that so long as the AutoScroll control has focus in the form, mouse-wheel scrolling should work without the user selecting the scrollbar itself. I suggest that rather than calling scrollBar.Select() to accomplish what you need, you instead call scrollBarParent.Focus(). This should take care of the flashing issue.
I am working with a WPF application that will be used on Windows tablets. The issue I am having is that I cannot scroll through a large multi-line TextBox on a tablet by pressing and dragging the content. However, it still scrolls on a desktop with a mouse wheel.
This question (Enable swipe scrolling on Textbox control in WPF Scrollviewer) seems to answer the same problem I am having, but I need to do it programmatically. This is what I am doing to set the panning mode of the TextBox:
txtLongText.SetValue(ScrollViewer.PanningModeProperty, PanningMode.None);
Which I can tell is working because the click & drag text selection is now disabled, but the content still does not scroll. I am also setting the panning mode of the outer ScrollViewer as such:
popupScrollView.PanningMode = PanningMode.Both;
The popupScrollView object is then being set as the content inside a Popup.
The only thing I can think of is if there is somewhere else higher up that I need to be setting the panning mode? Any help would be appreciated. Thanks.
i have same problem with touch devices. i have a tricky way to handle this kind of issues
You have to handle touch event manually
i have written some codes to handle touch events manually
when UIElement_OnTouchDown(object sender, TouchEventArgs e) event occurred you can keep position of touched position by eventArgs.GetTouchPoint(this).Position.Y.
after that, you can determine is scroll happened or not by watching the position changes.
here is my sample gist
, i use this approach for same issue with touch devices
I think you require to use three properties to achieve this.
ScrollViewer.PanningMode
ScrollViewer.PanningDeceleration
ScrollViewer.PanningRatio
By default, PanningMode sets to None, but set it to another value will enable touch scrolling.
Another thing you can try is to set ScrollViewer CanContentScroll to true.
While Im not sure there is a viable way to solve that using wpf only, I recommend trying to implement html UI inside your wpf application using DoNetBrowser, link.
Then you can use the textarea control in html, which in default lets you scroll on mobile.
Hope this answer helped you.
I have looked on stackoverflow and have not seen a solution (but may have missed it).
I want to scroll the datagridview contents with a swipe. A swipe gesture in Windows 8.1 seems to translate appropriately to a scroll event which causes the desired result. I can get the scroll event to show up if I have the scrollbar in the datagridview control. Consequently, to get scrolling to occur in the control with a swipe, I am looking for either (1) a way to have the scroll event occur without the scrollbar or (2) a way to hide the scrollbar. Option 1 is preferable since having the extraneous scrollbar around seems like a bit of a hack. I have a custom scrollbar outside of the datagridview which is why I want to hide the internal datagridview scrollbar.
Thanks for looking and any help you can provide.
I have a question, how to handle the scroll event when I scroll my mouse to adjust volume of a MediaElement?
I think you are looking for the UIElement.MouseWheel event.
I'd offer more, but I don't know how your app is structured. If you are using MVVM, etc.
I have some straight WPF 3.5 controls handling left mouse clicks that I need to use within a Surface app (SDK 1.0). The problem I am facing is that do not work by default. I am thinking of wrapping each control in a SurfaceContentControl and translating ContactTouchDown or ContactTapGesture events to corresponding MouseDown events.
The problem boils down to - how to "inject" or simulate arbitrary routed mouse events? I have tried InputManager.Current.ProcessInput() but didn't get very far. Any help is appreciated.
Try to use AutomationPeer classes. For example ButtonAutomationPeer is for Button. The code below initiates a click.
ButtonAutomationPeer peer = new ButtonAutomationPeer(button);
IInvokeProvider provider = (IInvokeProvider)peer.GetPattern(PatternInterface.Invoke);
provider.Invoke();
evpo's idea is an interesting one (though if you're working with custom controls, they rarely come with AutomationPeer classes).
You can't simply 'inject' mouse input by sending WM_MOUSE* events to your app... WPF would indeed process the message but when it goes to figure out the position of mouse for that event, it will query the actual mouse API instead of trying what you stick in the WM.
So really all you can do is tell windows to move the actual mouse cursor and act as though the button is being clicked/released. Some code you can use for that is in http://www.codeproject.com/KB/system/globalmousekeyboardlib.aspx
That said, while you can technically do this, it sucks... you've got an expensive multitouch device but are 1) showing a mouse cursor on it 2) limiting arbitrary parts of it to being used 'single touch' (and only one of those arbitrary parts at a time and 3) coming up with an arbitrary method of determining which finger you will treat as the mouse-controlling one