Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Windows Forms
  4. How to scroll two listbox together in c# ?

How to scroll two listbox together in c# ?

Scheduled Pinned Locked Moved Windows Forms
csharptutorialquestion
4 Posts 2 Posters 4 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nav_smec
    wrote on last edited by
    #1

    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.

    S 1 Reply Last reply
    0
    • N nav_smec

      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.

      S Offline
      S Offline
      ScottM1
      wrote on last edited by
      #2

      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.

      N 1 Reply Last reply
      0
      • S ScottM1

        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.

        N Offline
        N Offline
        nav_smec
        wrote on last edited by
        #3

        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)

        S 1 Reply Last reply
        0
        • N nav_smec

          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)

          S Offline
          S Offline
          ScottM1
          wrote on last edited by
          #4

          Thanks Will try this :)

          There are 10 types of people in the world, those who understand binary and those who dont.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups