/// <include file='doc\ScrollBar.uex' path='docs/doc[@for="ScrollBar.WmReflectScroll"]/*' /> /// <devdoc> /// </devdoc> /// <internalonly/> private void WmReflectScroll(ref Message m) { ScrollEventType id = (ScrollEventType)NativeMethods.Util.LOWORD(m.WParam); // For Rtl systems we need to swap increment and decrement // if (RightToLeft == RightToLeft.Yes) { switch (id) { case ScrollEventType.First: id = ScrollEventType.Last; break; case ScrollEventType.Last: id = ScrollEventType.First; break; case ScrollEventType.SmallDecrement: id = ScrollEventType.SmallIncrement; break; case ScrollEventType.SmallIncrement: id = ScrollEventType.SmallDecrement; break; case ScrollEventType.LargeDecrement: id = ScrollEventType.LargeIncrement; break; case ScrollEventType.LargeIncrement: id = ScrollEventType.LargeDecrement; break; } } int newValue = value; // The ScrollEventArgs constants are defined in terms of the windows // messages.. this eliminates confusion between the VSCROLL and // HSCROLL constants, which are identical. // switch (id) { case ScrollEventType.First: newValue = minimum; break; case ScrollEventType.Last: newValue = maximum - LargeChange + 1; // si.nMax - si.nPage + 1; break; case ScrollEventType.SmallDecrement: newValue = Math.Max(value - SmallChange, minimum); break; case ScrollEventType.SmallIncrement: newValue = Math.Min(value + SmallChange, maximum - LargeChange + 1); // max - lChange + 1); break; case ScrollEventType.LargeDecrement: newValue = Math.Max(value - LargeChange, minimum); break; case ScrollEventType.LargeIncrement: newValue = Math.Min(value + LargeChange, maximum - LargeChange + 1); // si.nPos + si.nPage,si.nMax - si.nPage + 1); break; case ScrollEventType.ThumbPosition: case ScrollEventType.ThumbTrack: NativeMethods.SCROLLINFO si = new NativeMethods.SCROLLINFO(); si.fMask = NativeMethods.SIF_TRACKPOS; SafeNativeMethods.GetScrollInfo(new HandleRef(this, Handle), NativeMethods.SB_CTL, si); if (RightToLeft == RightToLeft.Yes) { newValue = ReflectPosition(si.nTrackPos); } else { newValue = si.nTrackPos; } break; } ScrollEventArgs se = new ScrollEventArgs(id, newValue); OnScroll(se); Value = se.NewValue; }
private int AdjustScroll(Message m, int pos, int maxPos, bool horizontal) { switch (NativeMethods.Util.LOWORD(m.WParam)) { case NativeMethods.SB_THUMBPOSITION: case NativeMethods.SB_THUMBTRACK: NativeMethods.SCROLLINFO si = new NativeMethods.SCROLLINFO(); si.cbSize = Marshal.SizeOf(typeof(NativeMethods.SCROLLINFO)); si.fMask = NativeMethods.SIF_TRACKPOS; int direction = horizontal ? NativeMethods.SB_HORZ : NativeMethods.SB_VERT; if (SafeNativeMethods.GetScrollInfo(new HandleRef(this, m.HWnd), direction, si)) { pos = si.nTrackPos; } else { pos = NativeMethods.Util.HIWORD(m.WParam); } break; case NativeMethods.SB_LINEUP: if (pos > SCROLL_LINE) { pos -= SCROLL_LINE; } else { pos = 0; } break; case NativeMethods.SB_LINEDOWN: if (pos < maxPos - SCROLL_LINE) { pos += SCROLL_LINE; } else { pos = maxPos; } break; case NativeMethods.SB_PAGEUP: if (pos > SCROLL_PAGE) { pos -= SCROLL_PAGE; } else { pos = 0; } break; case NativeMethods.SB_PAGEDOWN: if (pos < maxPos - SCROLL_PAGE) { pos += SCROLL_PAGE; } else { pos = maxPos; } break; } return(pos); }