2

Im capturing the Scroll event in a flowLayoutPanel that contains a bunch of controls inside (textboxes). If I move the scrollbar with the mouse the Scroll event is correctly captured. But If jump from control to control using the tab key and the scrollbar moves to give the textbox focus the event is not raised. What can I do in that situation, I really need to capture no matter how the scroll is modified.

I uploaded a simple project where the problem could be shown http://1drv.ms/1UabHkv

mjsr
  • 7,410
  • 18
  • 57
  • 83

2 Answers2

1

You're looking for the GotFocus event. There is also a LostFocus event. It works for clicks, tabs, shift+tabs, and so on

textBox1.GotFocus += textBox1_ScrollEvent;

where textBox1_ScrollEvent is the event handler for the scrolling

Kelsey Abreu
  • 1,094
  • 3
  • 17
  • 42
  • but using that I will have to subscribe to every GotFocus event for each textbox that is inside the flowLayoutPanel and then in that code verify if the scroll has been moved. I think that is overkill, there must be a more clean approach. If no approach is found in a reasonable time I will put it as an answer. – mjsr Feb 18 '16 at 14:40
  • 1
    As I say, due that no alternative was found I used this approach. Hopefully it is not going to slow down too much the behaviour of the form. Thanks – mjsr Feb 24 '16 at 15:15
0

I don't think you are binding to the correct event. The docs for ScrollableControl.Scroll Event state:

The Scroll event occurs when the user scrolls through the client area by interacting with the scroll bars, or when the user navigates between controls and the active control scrolls into view. The Scroll event also occurs when you write code, such as setting the AutoScrollPosition property, that scrolls through the client area.

Edit: It would seem that the MS documentation is indeed incorrect. I've tested using both your sample project and one I created and I'm experiencing the same behaviour where the Scroll event is not firing on tab or even on mousewheel.

It would seem that the best course of action would be to implement your own scrollbars and turn Autoscroll off for your Panel.

See the following SO question for mroe information: How to use ScrollableControl with AutoScroll set to false

Community
  • 1
  • 1
Chris Pickford
  • 8,642
  • 5
  • 42
  • 73