Example #1
0
        private void vScroll_Scroll(object sender, System.Windows.Forms.ScrollEventArgs e)
        {
            ScrollInfoStruct sI = new ScrollInfoStruct();

            sI.fMask  = SIF_ALL;
            sI.cbSize = Marshal.SizeOf(sI);
            GetScrollInfo(listView.Handle, 1, ref sI);

            if (vScroll.Value != sI.nPos)
            {
                int scrollDifference = vScroll.Value - sI.nPos;
                if (scrollDifference < 0)
                {
                    scrollDifference = Math.Abs(scrollDifference);
                    for (int x = 0; x < scrollDifference; x++)
                    {
                        SendMessage(listView.Handle, 277, (IntPtr)0, (IntPtr)0);
                    }
                }
                else
                {
                    for (int x = 0; x < scrollDifference; x++)
                    {
                        SendMessage(listView.Handle, 277, (IntPtr)1, (IntPtr)0);
                    }
                }
            }
        }
Example #2
0
        private void hScroll_Scroll(object sender, System.Windows.Forms.ScrollEventArgs e)
        {
            ScrollInfoStruct sI = new ScrollInfoStruct();

            sI.fMask  = SIF_ALL;
            sI.cbSize = Marshal.SizeOf(sI);
            GetScrollInfo(listView.Handle, 0, ref sI);

            if (Math.Abs(hScroll.Value - sI.nPos) >= 6)
            {
                int scrollDifference = (int)Math.Round((double)((hScroll.Value - sI.nPos) / 6), 0);
                if (scrollDifference < 0)
                {
                    scrollDifference = Math.Abs(scrollDifference);
                    for (int x = 0; x < scrollDifference; x++)
                    {
                        SendMessage(listView.Handle, 276, (IntPtr)0, (IntPtr)0);
                    }
                    //GetScrollInfo(listView.Handle, 0, ref sI);
                    //int y0 = sI.nPos;
                    //SendMessage( listView.Handle,276,(IntPtr) 1,(IntPtr)0 );
                    //GetScrollInfo(listView.Handle, 0, ref sI);
                    //MessageBox.Show((sI.nPos - y0).ToString());
                }
                else
                {
                    for (int x = 0; x < scrollDifference; x++)
                    {
                        SendMessage(listView.Handle, 276, (IntPtr)1, (IntPtr)0);
                    }
                }
            }
        }
Example #3
0
        /// <summary>
        /// Scroll to a vertical position
        /// </summary>
        /// <param name="treeView">TreeView</param>
        /// <param name="si">Scroll information</param>
        public static void ScrollToPosition(TreeView treeView, ScrollInfoStruct si)
        {
            ScrollInfoStruct siOwn = new ScrollInfoStruct();

            siOwn.fMask  = NativeMethods.SIF_ALL;
            siOwn.cbSize = Marshal.SizeOf(si);

            NativeMethods.GetScrollInfo(treeView.Handle, NativeMethods.SB_VERT, ref siOwn);

            if (siOwn.nPos != si.nPos)
            {
                NativeMethods.SetScrollInfo(treeView.Handle.ToInt32(), NativeMethods.SB_VERT, ref si, true);
                NativeMethods.SendMessageLong(treeView.Handle.ToInt32(), NativeMethods.WM_VSCROLL,
                                              NativeMethods.SB_THUMBTRACK + 0x10000 * si.nPos, 0);
            }
        }
Example #4
0
        public int getHorizontalScrollPosition()
        {
            ScrollInfoStruct sInfo = new ScrollInfoStruct();

            sInfo.fMask  = 0x4; //(0x1 | 0x2 | 0x4 | 0x10);
            sInfo.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(sInfo);

            if (GetScrollInfo(this.Handle, 0x1, ref sInfo) >= 0)
            {
                return(sInfo.nPos);
            }
            else
            {
                return(-1);
            }
        }
Example #5
0
        protected override void WndProc(ref System.Windows.Forms.Message m)
        {
            base.WndProc(ref m);
            if (m.Msg == WM_VSCROLL)
            {

                ScrollInfoStruct si = new ScrollInfoStruct();
                si.fMask = SIF_ALL;
                si.cbSize = (int)Marshal.SizeOf(si);
                GetScrollInfo(m.HWnd, SB_VERT, ref si);
                if (m.WParam.ToInt32() == SB_ENDSCROLL)
                {
                    ScrollEventArgs sargs = new ScrollEventArgs(ScrollEventType.EndScroll, si.nPos);
                    this.OnScrollUp();
                }
                else this.OnScroll();
            }
            else if (m.Msg == WM_HSCROLL) this.OnScroll();
        }
Example #6
0
        protected override void WndProc(ref System.Windows.Forms.Message msg)
        {
            if (msg.Msg == WM_VSCROLL)
            {
                if (Scrolled != null)
                {
                    ScrollInfoStruct si = new ScrollInfoStruct();
                    Marshal.SizeOf(si);
                    GetScrollInfo(msg.HWnd, 0, ref si);

                    if (msg.WParam.ToInt32() == SB_ENDSCROLL)
                    {
                        ScrollEventArgs sargs = new ScrollEventArgs(
                            ScrollEventType.EndScroll,
                            si.nPos);
                        Scrolled(this, sargs);
                    }
                }
            }
            base.WndProc(ref msg);
        }
Example #7
0
        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)
                    {
                        ScrollEventArgs sargs = new ScrollEventArgs(
                            ScrollEventType.EndScroll,
                            si.nPos);
                        OnHorizontalScroll(this, sargs);
                    }
                }
            }
            if (msg.Msg == WM_VSCROLL)
            {
                if (OnVerticalScroll != 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)
                    {
                        ScrollEventArgs sargs = new ScrollEventArgs(
                            ScrollEventType.EndScroll,
                            si.nPos);
                        OnVerticalScroll(this, sargs);
                    }
                }
            }
            base.WndProc(ref msg);
        }
 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)
             {
                 ScrollEventArgs sargs = new ScrollEventArgs(
                 ScrollEventType.EndScroll,
                 si.nPos);
                 OnHorizontalScroll(this, sargs);
             }
         }
     }
     if (msg.Msg == WM_VSCROLL)
     {
         if (OnVerticalScroll != 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)
             {
                 ScrollEventArgs sargs = new ScrollEventArgs(
                 ScrollEventType.EndScroll,
                 si.nPos);
                 OnVerticalScroll(this, sargs);
             }
         }
     }
     base.WndProc(ref msg);
 }
Example #9
0
 protected override void WndProc(ref System.Windows.Forms.Message m)
 {
     base.WndProc(ref m);
     if (m.Msg == WM_VSCROLL)
     {
         ScrollInfoStruct si = new ScrollInfoStruct();
         si.fMask  = SIF_ALL;
         si.cbSize = (int)Marshal.SizeOf(si);
         GetScrollInfo(m.HWnd, SB_VERT, ref si);
         if (m.WParam.ToInt32() == SB_ENDSCROLL)
         {
             ScrollEventArgs sargs = new ScrollEventArgs(ScrollEventType.EndScroll, si.nPos);
             this.OnScrollUp();
         }
         else
         {
             this.OnScroll();
         }
     }
     else if (m.Msg == WM_HSCROLL)
     {
         this.OnScroll();
     }
 }
Example #10
0
 private static extern int GetScrollInfo(
     IntPtr hWnd, int n, ref ScrollInfoStruct lpScrollInfo);
        public int getHorizontalScrollPosition()
        {
            ScrollInfoStruct sInfo = new ScrollInfoStruct();
            sInfo.fMask = 0x4; //(0x1 | 0x2 | 0x4 | 0x10);
            sInfo.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(sInfo);

            if (GetScrollInfo(this.Handle, 0x1, ref sInfo)>=0)
            {
                return sInfo.nPos;
            }
            else
            {
                return -1;
            }
        }
Example #12
0
        private void RefreshScroller()
        {
            bool hVisible, vVisible;

            //Retrieve scroll info
            ScrollInfoStruct vSI = new ScrollInfoStruct();

            vSI.fMask  = SIF_ALL;
            vSI.cbSize = Marshal.SizeOf(vSI);
            GetScrollInfo(listView.Handle, 1, ref vSI);

            ScrollInfoStruct hSI = new ScrollInfoStruct();

            hSI.fMask  = SIF_ALL;
            hSI.cbSize = Marshal.SizeOf(hSI);
            GetScrollInfo(listView.Handle, 0, ref hSI);

            //Shall we even bother?
            if (
                hScroll.Value == hSI.nPos && hScroll.Maximum == hSI.nMax &&
                vScroll.Value == vSI.nPos && vScroll.Maximum == vSI.nMax
                )
            {
                return;
            }

            // Vertical Scroll Handling Pwns You!
            vScroll.LargeChange = vSI.nPage;
            vScroll.Minimum     = vSI.nMin;
            vScroll.Maximum     = vSI.nMax;
            vScroll.Value       = vSI.nPos;

            if ((vScroll.Maximum * 18 + 26) - vScroll.Height <= 1 || !vScroll.Enabled)
            {
                vScroll.Visible = false;
                vVisible        = false;
            }
            else
            {
                vScroll.Visible = true;
                vVisible        = true;
            }


            // Horizontal Scroll Handling Pwns You!
            hScroll.LargeChange = hSI.nPage;
            hScroll.SmallChange = hSI.nPage;
            hScroll.Minimum     = hSI.nMin;
            hScroll.Maximum     = hSI.nMax;
            hScroll.Value       = hSI.nPos;

            if (hScroll.Width - hScroll.Maximum > 0 || !hScroll.Enabled)
            {
                hScroll.Visible = false;
                hVisible        = false;
            }
            else
            {
                hScroll.Visible = true;
                hVisible        = true;
            }

            //Do we need to resize the scrollbars?


            if (hVisible && vVisible)
            {
                lblCornerCover.BackColor = this.BackColor;
                lblCornerCover.Visible   = true;
            }
            else
            {
                lblCornerCover.Visible = false;
            }

            if (hVisible)
            {
                vScroll.Height  = this.Height - 4 - hScroll.Height;
                vScroll.Visible = !vScroll.Visible;
                vScroll.Visible = !vScroll.Visible;
            }
            else
            {
                vScroll.Height = this.Height - 4;
            }

            if (vVisible)
            {
                hScroll.Width   = this.Width - 4 - vScroll.Width;
                hScroll.Visible = !hScroll.Visible;
                hScroll.Visible = !hScroll.Visible;
            }
            else
            {
                hScroll.Width = this.Width - 4;
            }
        }
 private static extern int GetScrollInfo(IntPtr hWnd, int n,
                           ref ScrollInfoStruct lpScrollInfo);
        /// <summary>
        /// Prevent the combobox dropdown from working
        /// http://stackoverflow.com/questions/5337834/prevent-dropdown-area-from-opening-of-combobox-control-in-windows-forms
        /// And make it possible to determine which index the user is currently hovering on
        /// http://www.codeproject.com/Articles/14255/ComboBox-firing-events-when-hovering-on-the-dropdo
        /// </summary>
        protected override void WndProc(ref  Message m)
        {
            if (!CanDropDown &&
               (m.Msg == 0x201 || // WM_LBUTTONDOWN
                m.Msg == 0x203)) // WM_LBUTTONDBLCLK
                return;

            if (m.Msg == 308)
            {
                Point LocalMousePosition = this.PointToClient(Cursor.Position);
                xPos = LocalMousePosition.X;
                yPos = LocalMousePosition.Y - this.Size.Height - 1;
                onScreenIndex = 0;

                int oldYPos = yPos;

                // get the 0-based index of where the cursor is on screen
                // as if it were inside the listbox
                while (yPos >= this.ItemHeight)
                {
                    yPos -= this.ItemHeight;
                    onScreenIndex++;
                }

                //if (yPos < 0) { onScreenIndex = -1; }
                ScrollInfoStruct si = new ScrollInfoStruct();
                si.fMask = SIF_ALL;
                si.cbSize = Marshal.SizeOf(si);
                // m.LParam holds the hWnd to the drop down list that appears
                int getScrollInfoResult = 0;
                getScrollInfoResult = GetScrollInfo(m.LParam, SB_VERT, ref si);

                // k returns 0 on error, so if there is no error add the current
                // track position of the scrollbar to our index
                if (getScrollInfoResult > 0)
                {
                    onScreenIndex += si.nTrackPos;
                }

                // Check we're actually inside the drop down window that appears and
                // not just over its scrollbar before we actually try to update anything
                // then if we are raise the Hover event for this comboBox
                if (!(xPos > this.Width || xPos < 1 ||
                      oldYPos < 0 || (oldYPos > this.ItemHeight *
                      this.MaxDropDownItems)))
                {
                    if (onScreenIndex > this.Items.Count - 1)
                        hoveredIndex = this.Items.Count - 1;
                    else
                        hoveredIndex = onScreenIndex;

                    //hoveredIndex = (onScreenIndex > this.Items.Count - 1) ?
                    //               this.Items.Count - 1 : onScreenIndex;
                }
                else
                    hoveredIndex = -1;
            }

            base.WndProc(ref m);
        }
Example #15
0
 static extern int SetScrollInfo(IntPtr hwnd, int fnBar, [In] ref ScrollInfoStruct
                                 lpScrollInfo, bool fRedraw);
Example #16
0
 public static extern int SetScrollInfo(
     IntPtr hWnd, int fnBar, ref ScrollInfoStruct lpScrollInfo, bool fRedraw);
Example #17
0
 public static extern int SetScrollInfo(IntPtr hWnd, int n,
                                        [MarshalAs(UnmanagedType.Struct)] ref ScrollInfoStruct lpcScrollInfo,
                                        bool b);
Example #18
0
		public static extern int SetScrollInfo(
			IntPtr hWnd, int fnBar, ref ScrollInfoStruct lpScrollInfo, bool fRedraw );
Example #19
0
 /// <summary>
 /// Returns the vertical scroll position
 /// </summary>
 /// <param name="treeView">TreeView</param>
 /// <param name="si">Scroll information</param>
 public static void GetScrollPosition(TreeView treeView, ref ScrollInfoStruct si)
 {
     si.fMask  = NativeMethods.SIF_ALL;
     si.cbSize = Marshal.SizeOf(si);
     NativeMethods.GetScrollInfo(treeView.Handle, NativeMethods.SB_VERT, ref si);
 }
Example #20
0
 internal static extern int SetScrollInfo(int hWnd, int n,
                                          [MarshalAs(UnmanagedType.Struct)] ref ScrollInfoStruct lpcScrollInfo,
                                          bool b);