/// <summary>
        /// vertical table scroll
        /// </summary>
        /// <param name="scrollEventType">Scroll Event Type</param>
        /// <param name="newPos">the new position</param>
        /// <param name="oldPos">the old position</param>
        /// <param name="scrollWindow">true, if we need to scroll the window right away</param>
        protected override void ScrollVertically(ScrollEventType scrollEventType, int newPos, int oldPos, bool scrollWindow)
        {
            NativeScroll.SCROLLINFO sc = ScrollInfo(NativeScroll.SB_VERT);
            int maxScroll = sc.nMax - sc.nPage + 1;

            if (newPos > maxScroll)
            {
                newPos = maxScroll;
            }
            if (newPos < 0)
            {
                newPos = 0;
            }

            NativeScroll.SetScrollPos(this.Handle, NativeScroll.SB_VERT, newPos, true);

            _topIndex = newPos - RecordsBeforeCurrentView;

            if (scrollWindow)
            {
                NativeWindowCommon.RECT rc = new NativeWindowCommon.RECT();
                rc.top    = ClientRectangle.Top + _header.Height;
                rc.left   = ClientRectangle.Left;
                rc.right  = ClientRectangle.Right;
                rc.bottom = ClientRectangle.Bottom;
                NativeScroll.ScrollWindowEx(this.Handle, 0, (oldPos - newPos) * RowHeight, ref rc, (IntPtr)null, (IntPtr)null, (IntPtr)null, 0);
            }
            base.ScrollVertically(scrollEventType, newPos, oldPos, scrollWindow);
        }
Example #2
0
 /// <summary>
 /// initialize horizontal scroll
 /// </summary>
 private void initHScroll()
 {
     NativeScroll.SCROLLINFO sc = ScrollInfo(NativeScroll.SB_HORZ);
     sc.nMax  = sc.nMin = sc.nPos = 0;
     sc.nPage = 0;
     sc.fMask = NativeScroll.SIF_RANGE | NativeScroll.SIF_POS | NativeScroll.SIF_PAGE;
     NativeScroll.SetScrollInfo(this.Handle, NativeScroll.SB_HORZ, ref sc, false);
 }
Example #3
0
        /// <summary>
        /// scroll info for scrollbar
        /// </summary>
        /// <param name="fnBar"></param>
        /// <returns></returns>
        public static NativeScroll.SCROLLINFO ScrollInfo(Control control, int fnBar)
        {
            NativeScroll.SCROLLINFO sc = new NativeScroll.SCROLLINFO();

            sc.fMask  = NativeScroll.SIF_ALL;
            sc.cbSize = Marshal.SizeOf(sc);
            bool res = NativeScroll.GetScrollInfo(control.Handle, fnBar, ref sc);

            return(sc);
        }
Example #4
0
        /// <summary>
        /// perform horizontal scroll
        /// </summary>
        /// <param name="value"></param>
        /// <param name="newValue"></param>
        private void ScrollHorizontally(int value, int newValue)
        {
            NativeScroll.SCROLLINFO sc = ScrollInfo(NativeScroll.SB_HORZ);
            int maxValue = sc.nMax - sc.nPage;

            if (newValue < 0)
            {
                newValue = 0;
            }
            if (newValue > maxValue)
            {
                newValue = maxValue;
            }
            NativeScroll.SetScrollPos(this.Handle, NativeScroll.SB_HORZ, newValue, true);
            NativeWindowCommon.RECT rc = new NativeWindowCommon.RECT();
            NativeScroll.ScrollWindowEx(this.Handle, value - newValue, 0, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero,
                                        ref rc, NativeScroll.SW_SCROLLCHILDREN | NativeScroll.SW_INVALIDATE | NativeScroll.SW_ERASE);
            _corner.X = getXCorner();
        }
Example #5
0
        /// <summary>
        /// this causes paint for the table scrollbar area after scrollbar disappear while using Windows Themes
        /// </summary>
        protected void HideVerticalScrollbarAnimationForWindowsThemes()
        {
            if (NativeWindowCommon.IsThemeActive())
            {
                NativeScroll.SCROLLINFO sc  = ScrollInfo(NativeScroll.SB_VERT); //force table to stop dragging when we hide scrollbar
                ScrollEventArgs         arg = new ScrollEventArgs(ScrollEventType.EndScroll, sc.nPos, sc.nPos, ScrollOrientation.VerticalScroll);
                this.OnScroll(arg);

                SuspendLayout();
                sc.nPos = 0;
                sc.nMin = 0;
                //For some reason, we need the following code
                // a. While dragging thumb: As in case of Defect #115454. After the scrollbar is displayed, try dragging the thumbbar upwards.
                //    It remains visible even after the scrollbar is hidden. The problem is fixed if nMax and nPage are set to 0.
                // b. While clicking on the scrollbar just above the thumb so that scroll will be hidden (as in case of defect #115331, RIA task)
                //    After hiding vertical scrollbar if column width is increased to display horizontal scrollbar and then the thumb on horizontal
                //    scroll bar is clicked, some area above horizontal scroll bar is grayed. The problem is fixed if nMax and nPage are set to 1.
                if (_isThumbDrag)
                {
                    sc.nMax = sc.nPage = 0;
                }
                else
                {
                    sc.nMax = sc.nPage = 1;
                }
                sc.fMask = NativeScroll.SIF_ALL;
                NativeScroll.SetScrollInfo(this.Handle, NativeScroll.SB_VERT, ref sc, true);

                NativeScroll.ShowScrollBar(this.Handle, NativeScroll.SB_VERT, false);

                isVerticalScrollBarVisible = false;
                ResumeLayout();
                NativeWindowCommon.RedrawWindow(this.Handle, IntPtr.Zero, IntPtr.Zero, NativeWindowCommon.RedrawWindowFlags.RDW_FRAME |
                                                NativeWindowCommon.RedrawWindowFlags.RDW_INVALIDATE);
                this._header.Refresh();
            }
            else
            {
                NativeScroll.ShowScrollBar(this.Handle, NativeScroll.SB_VERT, false);
            }
        }
Example #6
0
        /// <summary>
        /// update horizontal scrollbar
        /// </summary>
        protected virtual void updateHScroll()
        {
            if (HorizontalScrollBar)
            {
                int logWidth = getLogWidth();
                int curWidth = ClientSize.Width;
                int Xcorner  = getXCorner();

                SuspendLayout();
                //should be scrollbar
                if (logWidth > curWidth)
                {
                    int maxRange = logWidth - curWidth;
                    if (Xcorner > maxRange)
                    {
                        ScrollHorizontally(Xcorner, maxRange);
                    }

                    NativeScroll.SCROLLINFO sc = ScrollInfo(NativeScroll.SB_HORZ);
                    sc.nMax  = logWidth;
                    sc.nPage = curWidth;
                    sc.fMask = NativeScroll.SIF_PAGE | NativeScroll.SIF_RANGE;
                    NativeScroll.SetScrollInfo(this.Handle, NativeScroll.SB_HORZ, ref sc, false);

                    if (rightToLeftLayout)
                    {
                        int prevPos = 0, newPos;
                        prevPos = sc.nMax - sc.nPos;
                        newPos  = sc.nMax - prevPos;
                        if (newPos != sc.nPos)
                        {
                            ScrollHorizontally(sc.nPos, newPos);
                        }
                    }

                    if (!isHorizontalScrollBarVisible)
                    {
                        NativeScroll.ShowScrollBar(this.Handle, NativeScroll.SB_HORZ, true);
                        isHorizontalScrollBarVisible = true;
                    }
                }
                //no scrollbar
                else // if (logWidth <= curWidth)
                {
                    if (_prevLogWidth > _prevWidth)
                    {
                        ScrollHorizontally(Xcorner, 0);
                    }

                    //It seems that horizontal scrollbar is shown by default on displaying vertical scroll.
                    // May be even the otherway is true and hence there is a need to refresh vertical scrollbar's visibility in following code
                    // Anyway, hide it unconditionally. This fixes the issue of black area in table control
                    //if (isHorizontalScrollBarVisible)
                    {
                        NativeScroll.ShowScrollBar(this.Handle, NativeScroll.SB_HORZ, false);
                        NativeScroll.ShowScrollBar(this.Handle, NativeScroll.SB_VERT, isVscrollShown());
                        isHorizontalScrollBarVisible = false;
                    }
                }

                if ((_prevLogWidth > _prevWidth && logWidth <= curWidth) ||
                    (_prevLogWidth <= _prevWidth && logWidth > curWidth))
                {
                    if (HorizontalScrollVisibilityChanged != null)
                    {
                        HorizontalScrollVisibilityChanged(this, new EventArgs());
                    }
                }

                _prevLogWidth = logWidth;
                _prevWidth    = curWidth;
                _displayWidth = Math.Max(logWidth, curWidth);
                ResumeLayout();
            }
            else
            {
                // We need to update the display width even when there is no scrollbar so as to get correct cordinate in case of Rtl
                UpdateDisplayWidth();
            }
        }
Example #7
0
        /// <summary>
        /// Navigate the treeview to the path in the textbox. Must be called manually when CurrentPath changes.
        /// </summary>
        public void BrowseTo()
        {
            Cursor.Current = Cursors.WaitCursor;
            try
            {
                PopulateMyComputer();
                string textboxPath = txtPath.Text.ToLower();

                int      sentinel     = 1;
                TreeNode loopRootNode = nodeMyComputer;
                bool     network      = false;
                if (textboxPath.Contains(Desktop.ToLower()))
                {
                    loopRootNode = rootnodeDesktop;
                    if (textboxPath.Length == Desktop.Length)
                    {
                        loopRootNode.Expand();
                        loopRootNode.EnsureVisible();
                        return;
                    }
                }
                else if (textboxPath.Contains(MyDocuments.ToLower()))
                {
                    loopRootNode = nodeMyDocuments;
                    if (textboxPath.Length == MyDocuments.Length)
                    {
                        loopRootNode.Expand();
                        loopRootNode.EnsureVisible();
                        return;
                    }
                }
                else if (textboxPath == "my computer")
                {
                    loopRootNode.Expand();
                    loopRootNode.EnsureVisible();
                    return;
                }
                else if (textboxPath.StartsWith(@"\\"))
                {
                    loopRootNode = nodeEntireNetwork;
                    network      = true;
                }
                treeview1.SelectedNode = loopRootNode;
                if (!textboxPath.EndsWith(Seperator))
                {
                    textboxPath += Seperator;
                }

StartAgain:

                do
                {
                    foreach (TreeNode currNode in loopRootNode.Nodes)
                    {
                        string currNodePath = currNode.Tag.ToString().ToLower();
                        if (!currNodePath.EndsWith(Seperator))
                        {
                            currNodePath += Seperator;
                        }

                        if (textboxPath.StartsWith(currNodePath))
                        {
                            currNode.TreeView.Focus();
                            currNode.TreeView.SelectedNode = currNode;
                            //currNode.EnsureVisible();
                            NativeScroll.ScrollH(currNode, 37);
                            if (currNode.Nodes.Count > 0)
                            {
                                currNode.Expand();
                                loopRootNode = currNode;
                            }
                            else
                            {
                                if (textboxPath == currNodePath)
                                {
                                    sentinel = -1;
                                    break;
                                }
                                continue;
                            }
                            if (currNodePath.StartsWith(textboxPath))
                            {
                                sentinel = -1;
                                break;
                            }
                            goto StartAgain;
                        }
                        if (network)
                        {
                            loopRootNode = currNode;
                            goto StartAgain;
                        }
                    }
                    if (sentinel == -1)
                    {
                        break;
                    }
                    try
                    {
                        loopRootNode = loopRootNode.NextNode;
                    }
                    catch (Exception)
                    { } //no more nodes (not an error, so suppress)
                } while (sentinel >= 0);
            }
            catch (Exception e1)
            {
                MessageBox.Show("Error: " + e1.Message);
            }
            Cursor.Current = Cursors.Default;
        }
Example #8
0
        /// <summary>
        /// Update vertical scroll bar
        /// </summary>
        /// <param name="calculateRowsInPage">Calculate rows in page before updating scroll bar</param>
        protected override void updateVScroll(bool calculateRowsInPage)
        {
            bool visibleChanged = false;
            bool hScrollBarExisted;
            bool hScrollBarExists;

            if (SuspendPaint)
            {
                return;
            }

            if (calculateRowsInPage)
            {
                ComputeAndSetRowsInPage(false);
            }

            hScrollBarExisted = isHscrollShown();

            if (isVscrollShown())
            {
                if (isVerticalScrollBarVisible != isVscrollShown())
                {
                    // In case of thumb drag window is already locked, no need to lock again
                    if (RightToLeft == RightToLeft.Yes && !_isThumbDrag)
                    {
                        NativeWindowCommon.LockWindowUpdate(this.Handle);
                    }

                    NativeScroll.ShowScrollBar(this.Handle, NativeScroll.SB_VERT, true);

                    if (RightToLeft == RightToLeft.Yes && !_isThumbDrag)
                    {
                        NativeWindowCommon.LockWindowUpdate(IntPtr.Zero);
                    }

                    visibleChanged = true;
                }

                // Unlock window and update
                if (UnlockWindowDrawOnThumbDrag())
                {
                    this.Update();
                }

                NativeScroll.SCROLLINFO sc = ScrollInfo(NativeScroll.SB_VERT);
                sc.nPos  = _vScrollThumbPos;
                sc.nMax  = _virtualItemsCount;
                sc.nPage = PageSize;
                sc.fMask = NativeScroll.SIF_PAGE | NativeScroll.SIF_RANGE | NativeScroll.SIF_POS;
                NativeScroll.SetScrollInfo(this.Handle, NativeScroll.SB_VERT, ref sc, true);

                // lock drawing on the window
                LockWindowDrawOnThumbDrag();
            }
            else
            {
                // If the scrollbar was shown earlier (isVerticalScrollBarVisible is true) and is to be removed
                // now (isVscrollShown() is false)...
                if (isVerticalScrollBarVisible)
                {
                    if (RightToLeft == RightToLeft.Yes && !_isThumbDrag)
                    {
                        NativeWindowCommon.LockWindowUpdate(this.Handle);
                    }

                    // Also, handle scrollbar animation caused due to bug in Windows theme
                    HideVerticalScrollbarAnimationForWindowsThemes();

                    if (RightToLeft == RightToLeft.Yes && !_isThumbDrag)
                    {
                        NativeWindowCommon.LockWindowUpdate(IntPtr.Zero);
                    }

                    //...end thumb drag.
                    if (_isThumbDrag)
                    {
                        EndThumbDrag();
                    }

                    visibleChanged = true;
                }
            }

            hScrollBarExists = isHscrollShown();

            if (visibleChanged)
            {
                OnVScrollBarVisibleChanged(isVscrollShown(), hScrollBarExisted, hScrollBarExists);
            }

            isVerticalScrollBarVisible = isVscrollShown();
        }
        /// <summary>
        /// update vertical scroll bar
        /// </summary>
        protected override void updateVScroll(bool calculateRowsInPage)
        {
            bool visibleChanged = false;
            bool hScrollBarExisted;
            bool hScrollBarExists;

            if (calculateRowsInPage)
            {
                ComputeAndSetRowsInPage(false);
            }

            hScrollBarExisted = isHscrollShown();

            if (isVscrollShown())
            {
                if (isVerticalScrollBarVisible != isVscrollShown())
                {
                    NativeScroll.ShowScrollBar(this.Handle, NativeScroll.SB_VERT, true);
                    isVerticalScrollBarVisible = true;
                    visibleChanged             = true;
                }

                NativeScroll.SCROLLINFO sc = ScrollInfo(NativeScroll.SB_VERT);

                if (this.DesignMode)
                {
                    if (sc.nMax != 1)
                    {
                        sc.nMax = 1;
                        NativeScroll.SetScrollInfo(this.Handle, NativeScroll.SB_VERT, ref sc, true);
                    }
                }
                else if ((_virtualItemsCount != 0 && sc.nMax != _virtualItemsCount - 1) ||
                         (RowsInPage != 0 && sc.nPage != RowsInPage))
                {
                    sc.nMax  = _virtualItemsCount - 1;
                    sc.nPage = RowsInPage;
                    sc.nPos  = _topIndex + RecordsBeforeCurrentView;
                    sc.fMask = NativeScroll.SIF_PAGE | NativeScroll.SIF_RANGE | NativeScroll.SIF_POS;

                    NativeScroll.SetScrollInfo(this.Handle, NativeScroll.SB_VERT, ref sc, true);
                }
            }
            else
            {
                // If the scrollbar was shown earlier (isVerticalScrollBarVisible is true) and is to be removed
                // now (isVscrollShown() is false), handle scrollbar animation caused due to bug in Windows theme
                if (isVerticalScrollBarVisible)
                {
                    HideVerticalScrollbarAnimationForWindowsThemes();
                    visibleChanged = true;
                }
            }

            hScrollBarExists = isHscrollShown();

            if (visibleChanged)
            {
                OnVScrollBarVisibleChanged(isVscrollShown(), hScrollBarExisted, hScrollBarExists);
            }
        }