How to scroll two listbox together in c# ?
-
Hello All, I want to catch scroll event of a list box in C#. I want to use two list box, and when one is scrolled the another should automatically be scrolled. What should I do for that. Thanks.
-
Hallo, I am trying to do the same thing. Did you manage to figure this out? Thanks
There are 10 types of people in the world, those who understand binary and those who dont.
Hello smyer, First you made your own scrolling listbox using this code : using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; using System.ComponentModel; using System.Runtime.InteropServices; namespace myscrollList { class scrollList : System.Windows.Forms.ListBox { [Category("Action")] //public event ScrollEventHandler Scroll = null; private const int WM_HSCROLL = 0x114; private const int WM_VSCROLL = 0x115; public event ScrollEventHandler OnHorizontalScroll; public event ScrollEventHandler OnVerticalScroll; private const int SB_LINEUP = 0; private const int SB_LINELEFT = 0; private const int SB_LINEDOWN = 1; private const int SB_LINERIGHT = 1; private const int SB_PAGEUP = 2; private const int SB_PAGELEFT = 2; private const int SB_PAGEDOWN = 3; private const int SB_PAGERIGHT = 3; private const int SB_THUMBPOSITION = 4; private const int SB_THUMBTRACK = 5; private const int SB_PAGETOP = 6; private const int SB_LEFT = 6; private const int SB_PAGEBOTTOM = 7; private const int SB_RIGHT = 7; private const int SB_ENDSCROLL = 8; private const int SIF_TRACKPOS = 0x10; private const int SIF_RANGE = 0x1; private const int SIF_POS = 0x4; private const int SIF_PAGE = 0x2; private const int SIF_ALL = SIF_RANGE | SIF_PAGE | SIF_POS | SIF_TRACKPOS; [DllImport("user32.dll", SetLastError = true)] private static extern int GetScrollInfo( IntPtr hWnd, int n, ref ScrollInfoStruct lpScrollInfo); private struct ScrollInfoStruct { public int cbSize; public int fMask; public int nMin; public int nMax; public int nPage; public int nPos; public int nTrackPos; } protected override void WndProc(ref System.Windows.Forms.Message msg) { if (msg.Msg == WM_HSCROLL) { if (OnHorizontalScroll != null) { ScrollInfoStruct si = new ScrollInfoStruct(); si.fMask = SIF_ALL; si.cbSize = Marshal.SizeOf(si); GetScrollInfo(msg.HWnd, 0, ref si); if (msg.WParam.ToInt32() == SB_ENDSCROLL)
-
Hello smyer, First you made your own scrolling listbox using this code : using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; using System.ComponentModel; using System.Runtime.InteropServices; namespace myscrollList { class scrollList : System.Windows.Forms.ListBox { [Category("Action")] //public event ScrollEventHandler Scroll = null; private const int WM_HSCROLL = 0x114; private const int WM_VSCROLL = 0x115; public event ScrollEventHandler OnHorizontalScroll; public event ScrollEventHandler OnVerticalScroll; private const int SB_LINEUP = 0; private const int SB_LINELEFT = 0; private const int SB_LINEDOWN = 1; private const int SB_LINERIGHT = 1; private const int SB_PAGEUP = 2; private const int SB_PAGELEFT = 2; private const int SB_PAGEDOWN = 3; private const int SB_PAGERIGHT = 3; private const int SB_THUMBPOSITION = 4; private const int SB_THUMBTRACK = 5; private const int SB_PAGETOP = 6; private const int SB_LEFT = 6; private const int SB_PAGEBOTTOM = 7; private const int SB_RIGHT = 7; private const int SB_ENDSCROLL = 8; private const int SIF_TRACKPOS = 0x10; private const int SIF_RANGE = 0x1; private const int SIF_POS = 0x4; private const int SIF_PAGE = 0x2; private const int SIF_ALL = SIF_RANGE | SIF_PAGE | SIF_POS | SIF_TRACKPOS; [DllImport("user32.dll", SetLastError = true)] private static extern int GetScrollInfo( IntPtr hWnd, int n, ref ScrollInfoStruct lpScrollInfo); private struct ScrollInfoStruct { public int cbSize; public int fMask; public int nMin; public int nMax; public int nPage; public int nPos; public int nTrackPos; } protected override void WndProc(ref System.Windows.Forms.Message msg) { if (msg.Msg == WM_HSCROLL) { if (OnHorizontalScroll != null) { ScrollInfoStruct si = new ScrollInfoStruct(); si.fMask = SIF_ALL; si.cbSize = Marshal.SizeOf(si); GetScrollInfo(msg.HWnd, 0, ref si); if (msg.WParam.ToInt32() == SB_ENDSCROLL)