读书人

怎么使两个一样的panel同步竖直滚动

发布时间: 2012-05-24 11:55:41 作者: rapoo

如何使两个一样的panel同步竖直滚动
在一个C#的应用程序中,有两个一模一样的panel,如何使它们同步滚动?
private void panel1_Scroll(object sender, ScrollEventArgs e)
{
if (e.ScrollOrientation == ScrollOrientation.VerticalScroll)
{
panel2.VerticalScroll.Value = e.NewValue;
}
else
{
panel2.HorizontalScroll.Value = e.NewValue;
}
}

private void panel2_Scroll(object sender, ScrollEventArgs e)
{
if (e.ScrollOrientation == ScrollOrientation.VerticalScroll)
{
panel1.VerticalScroll.Value = e.NewValue;
}
else
{
panel1.HorizontalScroll.Value = e.NewValue;
}
}

用了以上两个函数,发现滚动左边,右边panel可以滚动,但是不一致;滚动右边,左边没反应!是没法同步的!

请问除了这个方法外还有其他的吗?

[解决办法]
两个panel的Scroll事件指向同一个处理程序

C# code
this.panel1.Scroll += new System.Windows.Forms.ScrollEventHandler(this.panel1_Scroll);this.panel2.Scroll += new System.Windows.Forms.ScrollEventHandler(this.panel1_Scroll);       private void panel1_Scroll(object sender, ScrollEventArgs e)        {            if(e.ScrollOrientation == ScrollOrientation.VerticalScroll)            {                this.panel1.VerticalScroll.Value = e.NewValue;                this.panel2.VerticalScroll.Value = e.NewValue;            }            if (e.ScrollOrientation == ScrollOrientation.HorizontalScroll)            {                this.panel1.HorizontalScroll.Value = e.NewValue;                this.panel2.HorizontalScroll.Value = e.NewValue;            }                    }
[解决办法]
探讨

引用:

引用:

引用:

两个panel的Scroll事件指向同一个处理程序
C# code

this.panel1.Scroll += new System.Windows.Forms.ScrollEventHandler(this.panel1_Scroll);
this.panel2.Scroll += new……

读书人网 >C#

热点推荐