滚动2板,同时 [英] Scroll 2 panels at the same time

查看:133
本文介绍了滚动2板,同时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Windows窗体(.NET 2.0)控件包含内部splicontainer。 SplitContainer的,因为通常情况下,包含2个面板(标准的东西)。自动滚屏设置为true。

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.

我一直在挣扎相当一段时间来实现类似的同步这两个面板,所以滚动这些人会滚动,第二个也。我做到了这一点 - 通过Scroll事件(不是问题。)

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).

然而,当我们通过控制面板上的一项(如文本框)跨栏这一事件不叫 - 不是真的很喜欢它的msdn.microsoft.com/en-us/library/system.windows .forms.scrollablecontrol.scroll.aspx(以下简称Scroll事件通过与滚动条互动,通过客户区用户滚动时发生时,或当用户的控制和主动控制滚动到视图中。之间导航

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 :|

我所知道的一个事实,即包含在一个可滚动控制不可见的控制给予重点调用它的ScrollToControl(控制)事件,制造新的控件(文本框)可见。为了让更多的细节,我可以说这两个面板相同的(大小和控制)。

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?

推荐答案

下面正是你需要滚动2板在的 SplitContainer的。这将滚动,即使你跳格,以控制在当前视图。

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;
   }
}

这篇关于滚动2板,同时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆