From 72b9f56e743b188428ed60b953b4e1b8ee7ee52d Mon Sep 17 00:00:00 2001 From: Markus Hofknecht Date: Sun, 9 Jan 2022 17:13:10 +0100 Subject: [PATCH] [Feature] Swipe scrolling on touchscreen (#275), version 1.2.1.4 --- Business/Menus.cs | 20 ++++++++++++++++---- Properties/AssemblyInfo.cs | 4 ++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/Business/Menus.cs b/Business/Menus.cs index 396a5c7..cc0a1fe 100644 --- a/Business/Menus.cs +++ b/Business/Menus.cs @@ -1038,14 +1038,17 @@ namespace SystemTrayMenu.Business if (newRow > -1) { int delta = dragSwipeScrollingStartRowIndex - newRow; - DoScroll(dgv, delta * 2); - dragSwipeScrollingStartRowIndex += delta; + if (DoScroll(dgv, ref delta)) + { + dragSwipeScrollingStartRowIndex += delta; + } } } } - private void DoScroll(DataGridView dgv, int delta) + private bool DoScroll(DataGridView dgv, ref int delta) { + bool scrolled = false; if (delta != 0) { if (delta < 0 && dgv.FirstDisplayedScrollingRowIndex == 0) @@ -1053,15 +1056,24 @@ namespace SystemTrayMenu.Business delta = 0; } - int newFirstDisplayedScrollingRowIndex = dgv.FirstDisplayedScrollingRowIndex + delta; + int newFirstDisplayedScrollingRowIndex = dgv.FirstDisplayedScrollingRowIndex + (delta * 2); + + if (newFirstDisplayedScrollingRowIndex < 0 || newFirstDisplayedScrollingRowIndex >= dgv.RowCount) + { + newFirstDisplayedScrollingRowIndex = dgv.FirstDisplayedScrollingRowIndex + delta; + } + if (newFirstDisplayedScrollingRowIndex > -1 && newFirstDisplayedScrollingRowIndex < dgv.RowCount) { isDragSwipeScrolled = true; dgv.FirstDisplayedScrollingRowIndex = newFirstDisplayedScrollingRowIndex; Menu menu = (Menu)dgv.FindForm(); menu.AdjustScrollbar(); + scrolled = dgv.FirstDisplayedScrollingRowIndex == newFirstDisplayedScrollingRowIndex; } } + + return scrolled; } private void Dgv_MouseDown(object sender, MouseEventArgs e) diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index cc3e84f..58cad4d 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -39,5 +39,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.2.1.3")] -[assembly: AssemblyFileVersion("1.2.1.3")] +[assembly: AssemblyVersion("1.2.1.4")] +[assembly: AssemblyFileVersion("1.2.1.4")]