void UpdateScroll() { GDI.SCROLLINFO si = new GDI.SCROLLINFO(); si.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(typeof(GDI.SCROLLINFO)); si.fMask = (int)(GDI.ScrollInfoMask.SIF_RANGE | GDI.ScrollInfoMask.SIF_POS | GDI.ScrollInfoMask.SIF_PAGE); double xpc = (m_view.Left - m_physExtents.Left) / m_physExtents.Width; double wpc = m_view.Width / m_physExtents.Width; si.nPos = (int)(xpc * ScrollScale); si.nMin = 0; si.nMax = (int)ScrollScale; si.nPage = (int)(wpc * ScrollScale); GDI.SetScrollInfo(Handle, (int)GDI.ScrollBarDirection.SB_HORZ, ref si, true); double ypc = (m_view.Top - m_physExtents.Top) / m_physExtents.Height; double hpc = m_view.Height / m_physExtents.Height; si.nPos = (int)(ypc * ScrollScale); si.nMin = 0; si.nMax = (int)ScrollScale; si.nPage = (int)(hpc * ScrollScale); GDI.SetScrollInfo(Handle, (int)GDI.ScrollBarDirection.SB_VERT, ref si, true); }
void UpdateScroll() { GDI.SCROLLINFO si = new GDI.SCROLLINFO(); si.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(typeof(GDI.SCROLLINFO)); si.fMask = (int)(GDI.ScrollInfoMask.SIF_RANGE | GDI.ScrollInfoMask.SIF_POS | GDI.ScrollInfoMask.SIF_PAGE); si.nPos = (int)(m_view.Left - m_physExtents.Left); si.nMin = 0; si.nMax = (int)m_physExtents.Size.X; si.nPage = (int)m_view.Width; GDI.SetScrollInfo(Handle, (int)GDI.ScrollBarDirection.SB_HORZ, ref si, true); si.nPos = (int)(m_view.Top - m_physExtents.Top); si.nMin = 0; si.nMax = (int)m_physExtents.Size.Y; si.nPage = (int)m_view.Height; GDI.SetScrollInfo(Handle, (int)GDI.ScrollBarDirection.SB_VERT, ref si, true); }
protected void OnScroll(ScrollEventArgs se) { bool hasViewChanged = false; if (se.ScrollOrientation == ScrollOrientation.HorizontalScroll) { GDI.SCROLLINFO si = new GDI.SCROLLINFO(); si.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(typeof(GDI.SCROLLINFO)); si.fMask = (int)(GDI.ScrollInfoMask.SIF_TRACKPOS | GDI.ScrollInfoMask.SIF_PAGE | GDI.ScrollInfoMask.SIF_POS); GDI.GetScrollInfo(Handle, (int)GDI.ScrollBarDirection.SB_HORZ, ref si); switch (se.Type) { case ScrollEventType.LargeDecrement: m_view = new RectD(m_view.Left - m_view.Width, m_view.Top, m_view.Right - m_view.Width, m_view.Bottom); break; case ScrollEventType.LargeIncrement: m_view = new RectD(m_view.Left + m_view.Width, m_view.Top, m_view.Right + m_view.Width, m_view.Bottom); break; case ScrollEventType.SmallDecrement: m_view = new RectD(m_view.Left - m_view.Width * 0.1f, m_view.Top, m_view.Right - m_view.Width * 0.1f, m_view.Bottom); break; case ScrollEventType.SmallIncrement: m_view = new RectD(m_view.Left + m_view.Width * 0.1f, m_view.Top, m_view.Right + m_view.Width * 0.1f, m_view.Bottom); break; case ScrollEventType.ThumbTrack: { double tp = si.nTrackPos / ScrollScale * m_physExtents.Width + m_physExtents.Left; m_view = new RectD(tp, m_view.Top, tp + m_view.Width, m_view.Bottom); } break; } ClampView(); UpdateScroll(); Invalidate(); hasViewChanged = true; } else if (se.ScrollOrientation == ScrollOrientation.VerticalScroll) { GDI.SCROLLINFO si = new GDI.SCROLLINFO(); si.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(typeof(GDI.SCROLLINFO)); si.fMask = (int)(GDI.ScrollInfoMask.SIF_TRACKPOS | GDI.ScrollInfoMask.SIF_PAGE | GDI.ScrollInfoMask.SIF_POS); GDI.GetScrollInfo(Handle, (int)GDI.ScrollBarDirection.SB_VERT, ref si); switch (se.Type) { case ScrollEventType.LargeDecrement: m_view = new RectD(m_view.Left, m_view.Top - m_view.Height, m_view.Right, m_view.Bottom - m_view.Height); break; case ScrollEventType.LargeIncrement: m_view = new RectD(m_view.Left, m_view.Top + m_view.Height, m_view.Right, m_view.Bottom + m_view.Height); break; case ScrollEventType.SmallDecrement: m_view = new RectD(m_view.Left, m_view.Top - m_view.Height * 0.1f, m_view.Right, m_view.Bottom - m_view.Height * 0.1f); break; case ScrollEventType.SmallIncrement: m_view = new RectD(m_view.Left, m_view.Top + m_view.Height * 0.1f, m_view.Right, m_view.Bottom + m_view.Height * 0.1f); break; case ScrollEventType.ThumbTrack: { double tp = si.nTrackPos / ScrollScale * m_physExtents.Height + m_physExtents.Top; m_view = new RectD(m_view.Left, tp, m_view.Right, tp + m_view.Height); } break; } ClampView(); UpdateScroll(); Invalidate(); hasViewChanged = true; } if (hasViewChanged) { OnViewChanged(); } }