private void ApplyScroll(RichTextBox Source, RichTextBox Target, ScrollBarDirection Direction)
        {
            // unhook target from relevant event, otherwise we end up in an infinite loop!
            switch (Direction)
            {
                case ScrollBarDirection.SB_VERT:
                    {
                        Target.VScroll -= rtb_VScroll;
                    }
                    break;
                case ScrollBarDirection.SB_HORZ:
                    {
                        Target.HScroll -= rtb_HScroll;
                    }
                    break;
            }

            IntPtr ptrLparam = new IntPtr(0);
            IntPtr ptrWparam;

            // Prepare scroll info struct
            SCROLLINFO si = new SCROLLINFO();
            si.cbSize = (uint)Marshal.SizeOf(si);
            si.fMask = (uint)ScrollInfoMask.SIF_ALL;

            // Get current scroller posion
            GetScrollInfo(Source.Handle, (int)Direction, ref si);

            // if we're tracking, set target to current track position
            if ((si.nTrackPos > 0) || ((si.nTrackPos == 0) && (si.nPos != 0)))
            {
                si.nPos = si.nTrackPos;
            }

            // Reposition scroller
            SetScrollInfo(Target.Handle, (int)Direction, ref si, true);
            ptrWparam = new IntPtr(SB_THUMBTRACK + 0x10000 * si.nPos);

            // send the relevant message to the target control, and rehook the event
            switch (Direction)
            {
                case ScrollBarDirection.SB_VERT:
                    {
                        SendMessage(Target.Handle, WM_VSCROLL, ptrWparam, ptrLparam);
                        Target.VScroll += new EventHandler(this.rtb_VScroll);
                    }
                    break;
                case ScrollBarDirection.SB_HORZ:
                    {
                        SendMessage(Target.Handle, WM_HSCROLL, ptrWparam, ptrLparam);
                        Target.HScroll += new EventHandler(this.rtb_HScroll);
                    }
                    break;
            }
        }
Example #2
0
        public static int GetScrollPosition(Control control, ScrollBarDirection direction)
        {
            var si = new SCROLLINFO
            {
                cbSize = Marshal.SizeOf <SCROLLINFO>(),
                fMask  = ScrollInfoMask.SIF_POS,
            };

            if (NativeMethods.GetScrollInfo(control.Handle, direction, ref si) == 0)
            {
                throw new Win32Exception();
            }

            return(si.nPos);
        }
Example #3
0
 private static extern int GetScrollInfo(IntPtr hWnd, ScrollBarDirection fnBar, ref SCROLLINFO lpsi);
Example #4
0
 public static bool GetScrollInfo(Control ctrl, ref SCROLLINFO si, ScrollBarDirection scrollBarDirection)
 {
     if (ctrl != null)
     {
         si.cbSize = (uint)Marshal.SizeOf(si);
         si.fMask = (int)ScrollInfoMask.SIF_ALL;
         if (GetScrollInfo(ctrl.Handle, (int)scrollBarDirection, ref si))
             return true;
     }
     return false;
 }
Example #5
0
 public static extern bool ShowScrollBar(IntPtr hwnd, ScrollBarDirection scrollBar, bool show);
Example #6
0
 public void HideScrollBar(ScrollBarDirection type)
 {
     ShowScrollBar(this.Handle, (int)type, false);
 }
Example #7
0
 private static extern int GetScrollInfo(IntPtr hWnd, ScrollBarDirection fnBar, ref SCROLLINFO lpsi);
Example #8
0
 public static extern bool ShowScrollBar(IntPtr hwnd, ScrollBarDirection scrollBar, [MarshalAs(UnmanagedType.Bool)] bool show);
Example #9
0
 public static extern bool ShowScrollBar(IntPtr hwnd, ScrollBarDirection scrollBar, bool show);
Example #10
0
        public static int GetScrollPosition(Control control, ScrollBarDirection direction)
        {
            var si = new SCROLLINFO
            {
                cbSize = Marshal.SizeOf<SCROLLINFO>(),
                fMask = ScrollInfoMask.SIF_POS,
            };

            if (NativeMethods.GetScrollInfo(control.Handle, direction, ref si) == 0)
                throw new Win32Exception();

            return si.nPos;
        }
Example #11
0
 public static extern bool ShowScrollBar(IntPtr hwnd, ScrollBarDirection scrollBar, [MarshalAs(UnmanagedType.Bool)] bool show);
Example #12
0
 public static extern bool ShowScrollBar(IntPtr hWnd, ScrollBarDirection wBar, bool bShow);