/// <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); }
/// <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); } }
/// <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(); } }
/// <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); } }