I have windows forms (.net 2.0) control that contains a splicontainer inside. Splitcontainer, as usually, contains 2 panels (standard thing). The Autoscroll is set to true.
I've been struggling for quite a time to achieve something like synchronizing those two panels, so scrolling one of these will scroll the second one also. I achieved it - using Scroll event (not a problem).
However, this event is not called when we're tabbing through controls on the one of the panels (e.g. textboxes) - not really like what it's on the msdn.microsoft.com/en-us/library/system.windows.forms.scrollablecontrol.scroll.aspx ("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. ".
So, in fact, the panels are not really synchronized :|
I'm aware of the fact, that giving focus to not visible control contained in a scrollable control calls it's ScrollToControl(Control) event which "makes" the new control(textbox) visible. To give more details, I can say that both panels are identical (size and controls).
How would you achieve what I'm looking for?
Why don't you place the split container completely in a scrolling thingy instead of putting the scrollbar thingies inside the split container? That way they naturally share the same scrollbar and the split container can be as wide as necessary to fit the entire form.
I took the answer from @SwDevMan81 and rounded it out with the last piece I needed to get it work in VS 2012, .Net 4.5.
Part 1 is inside my form class:
Part 2 is in the constructor for the Form. I had to add events for the Scroll events themselves.
Here is exactly what you need to scroll 2 panels in a SplitContainer. This will scroll even if you are tabbing to controls not in the current view.