0

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.

user3700562
  • 693
  • 11
  • 23
  • Can you show the scroll code and from where are you calling *scrollBar.Select()*? – γηράσκω δ' αεί πολλά διδασκόμε Aug 10 '18 at 23:58
  • It's actually code straight from Microsoft and it's used in their System.ComponentModel.Design.ByteViewer class. There's some example code on [MSDN](https://msdn.microsoft.com/en-us/library/system.componentmodel.design.byteviewer(v=vs.110).aspx#Anchor_8) that you can run and it demonstrates the problem nicely. I have since looked at the implementation of VScrollBar and it's a simple wrapper for the ancient WINAPI scrollbar so I don't think there's a simple way to change that behaviour. – user3700562 Aug 11 '18 at 10:32

1 Answers1

0

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.

  • Why is it so difficult to scroll with keyboard? You intersept the *key-up or down* and send the *WM_SCROLL* message to parent if it is autoscroll or to the vertical scroll bar itself with the *LOWORD WPARAM* *SB_LINEDOWN or SB_LINEUP*. [WM_VSCROLL message](https://learn.microsoft.com/en-us/windows/desktop/controls/wm-vscroll) – γηράσκω δ' αεί πολλά διδασκόμε Aug 11 '18 at 00:02
  • I’ve never tried it myself. I am referencing information I’ve seen in other answers. If you have done it successfully before, perhaps you could provide an answer with details. –  Aug 11 '18 at 01:06
  • Thanks, I have now done something similar. Instead of calling Select() on the Scrollbar control, I have overridden OnMouseWheel and OnKeyDown in the parent and forward the events to the scrollbar control. – user3700562 Aug 11 '18 at 10:40