我有两个ListBoxAdv1和ListBoxAdv2,我希望同步它们滚动 我使用此代码只是向上或向下滚动,但没有更新显示其他ListBoxAdv中的项目 我该怎么办? 请帮忙
我试试这个:
private void listBoxAdv1_Scroll(object sender, ScrollEventArgs e)
{
listBoxAdv2.VScrollBar.Value = listBoxAdv1.VScrollBar.Value;
}
private void listBoxAdv2_Scroll(object sender, ScrollEventArgs e)
{
listBoxAdv1.VScrollBar.Value = listBoxAdv2.VScrollBar.Value;
}
和此:
private void listBoxAdv1_Scroll(object sender, ScrollEventArgs e)
{
listBoxAdv2.Focus();
ScrollEventArgs scrollEventArgs = new ScrollEventArgs(ScrollEventType.SmallIncrement, e.OldValue, e.NewValue, ScrollOrientation.VerticalScroll);
listBoxAdv2_Scroll(listBoxAdv2, scrollEventArgs);
}
private void listBoxAdv2_Scroll(object sender, ScrollEventArgs e)
{
}
答案 0 :(得分:-1)
感谢许多回复! 我找到了解决方案:
bool Scrolling = true;
private void listBoxAdv1_Scroll(object sender, ScrollEventArgs e)
{
if (Scrolling == true)
{
Scrolling = false;
listBoxAdv2.BeginUpdate();
listBoxAdv2.AutoScrollPosition = new Point(listBoxAdv1.AutoScrollPosition.X, listBoxAdv1.AutoScrollPosition.Y);
listBoxAdv2_Scroll(sender, e);
listBoxAdv2.EndUpdate();
Scrolling = true;
}
}
private void listBoxAdv2_Scroll(object sender, ScrollEventArgs e)
{
if (Scrolling == true)
{
Scrolling = false;
listBoxAdv1.BeginUpdate();
listBoxAdv1.AutoScrollPosition = new Point(listBoxAdv2.AutoScrollPosition.X, listBoxAdv2.AutoScrollPosition.Y);
listBoxAdv1_Scroll(sender, e);
listBoxAdv1.EndUpdate();
Scrolling = true;
}
}