0

I want to compare two text files like below, so I want to add one slide bar, as we side down it will slide both list boxes simultaneously on the same index and slide bar can go till the end to biggest Listbox. Just like any file compares software e.g. Beyond compare.

Thank you.

enter image description here

nick
  • 610
  • 5
  • 11

1 Answers1

1

You can do it like this by using the Scroll event. Both scrollbars need to handle the Scroll event like so:

private void vScrollBar1_Scroll(object sender, ScrollEventArgs e)
{
    this.vScrollBar2.Scroll -= vScrollBar2_Scroll;
    this.vScrollBar2.Value = (sender as ScrollBar).Value;
    this.vScrollBar2.Scroll += vScrollBar2_Scroll;
}

private void vScrollBar2_Scroll(object sender, ScrollEventArgs e)
{
    this.vScrollBar1.Scroll -= vScrollBar1_Scroll;
    this.vScrollBar1.Value = (sender as ScrollBar).Value;
    this.vScrollBar1.Scroll -= vScrollBar1_Scroll;
}

Please note when vScrollBar1 is scrolling, we will tell vScrollBar2 to scroll. Therefore, we do not want to trigger vScrollBar2.Scroll since it will come back and tell vScrollBar1 to scroll at that instance (circular calls). Therefore we unsubscribe vScrollBar2.Scroll event temporarily. After vScrollBar2 has scroll to the same position as vScrollBar1, then we tell vScrollBar2 tp subscribe to its scroll event again. The same story with the other scrollbar.

CodingYoshi
  • 25,467
  • 4
  • 62
  • 64