private void InfiniteReader_MouseWheel(object sender, MouseEventArgs e) { bool zooming = false; if (RawInput.IsPressed(VirtualKeys.Control)) { zooming = true; if (e.Delta > 0) { scale *= 1.41f; } else { scale /= 1.41f; } this.Invalidate(); } int movement = -e.Delta; float maximumScroll = float.MaxValue; //Don't allow scrolling if the last visible page is the last page available if (movement > 0 || zooming) { if (provider.IsLastPage(lastVisiblePage)) { maximumScroll = GetFitDimensions(CurrentPage).Height; for (int i = buffer + 1; i < loadedPages.Count; i++) { if (loadedPages[i] == null) { break; } maximumScroll += GetFitDimensions(loadedPages[i]).Height; } maximumScroll -= Height; } } else if (movement < 0) { if (provider.IsFirstPage(CurrentPage)) { scrollOffset = Math.Max(0, scrollOffset + movement); this.Invalidate(); return; } } if (zooming) { return; } scrollOffset = (int)(Math.Min(maximumScroll, scrollOffset + movement)); RefetchPages(); int scaledPageHeight = GetFitDimensions(CurrentPage).Height; if (scrollOffset > scaledPageHeight) { while (scrollOffset > scaledPageHeight) { MoveToNextPage(); scrollOffset = scrollOffset - scaledPageHeight; scaledPageHeight = GetFitDimensions(CurrentPage).Height; } } else if (scrollOffset < 0) { while (scrollOffset < 0) { MoveToPreviousPage(); scrollOffset += GetFitDimensions(CurrentPage).Height; } } this.Invalidate(); }