views:

623

answers:

2

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?

A: 

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.

Martijn
errr.Splitcontainer has 2 controls = panels.They both are too big to fit, so they need to have separate scrollbars.I hope that clears a bit.
I don't have much experience with C# GUIs, but in Java/Swing you can put the 2 big controls in one giant split container in such a way that the split container is big enough to hold them. Of course, such a big split container won't fit in your window so you put it in a scroll pane. I'd be very surprised if you couldn't do this in C# too.
Martijn
do you know what is splitcontainer? it has 2 panels and a splitbar. Sure you can create a big one, that will hold 2 panels, but the idea is to let these panels have independant scrollable area.
+1  A: 

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.


this.splitContainer1.Panel1.Paint += new System.Windows.Forms.PaintEventHandler(PanelPaint);
this.splitContainer1.Panel2.Paint += new System.Windows.Forms.PaintEventHandler(PanelPaint);

Point mPrevPan1Pos = new Point();
Point mPrevPan2Pos = new Point();

void PanelPaint(object sender, System.Windows.Forms.PaintEventArgs e)
{
   if (splitContainer1.Panel1.AutoScrollPosition != mPrevPan1Pos)
   {
      splitContainer1.Panel2.AutoScrollPosition = new System.Drawing.Point(-splitContainer1.Panel1.AutoScrollPosition.X, -splitContainer1.Panel1.AutoScrollPosition.Y);
      mPrevPan1Pos = splitContainer1.Panel1.AutoScrollPosition;
   }
   else if (splitContainer1.Panel2.AutoScrollPosition != mPrevPan2Pos)
   {
      splitContainer1.Panel1.AutoScrollPosition = new System.Drawing.Point(-splitContainer1.Panel2.AutoScrollPosition.X, -splitContainer1.Panel2.AutoScrollPosition.Y);
      mPrevPan2Pos = splitContainer1.Panel2.AutoScrollPosition;
   }
}
SwDevMan81