#develop (short for SharpDevelop) is a free IDE for .NET programming languages.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

39 lines
1.3 KiB

// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Windows.Forms;
namespace ICSharpCode.SharpDevelop.Widgets
{
/// <summary>
/// Accumulates mouse wheel deltas and reports the actual number of lines to scroll.
/// </summary>
public sealed class MouseWheelHandler
{
// CODE DUPLICATION: See ICSharpCode.TextEditor.Util.MouseWheelHandler
const int WHEEL_DELTA = 120;
int mouseWheelDelta;
public int GetScrollAmount(MouseEventArgs e)
{
// accumulate the delta to support high-resolution mice
mouseWheelDelta += e.Delta;
Console.WriteLine("Mouse rotation: new delta=" + e.Delta + ", total delta=" + mouseWheelDelta);
int linesPerClick = Math.Max(SystemInformation.MouseWheelScrollLines, 1);
int scrollDistance = mouseWheelDelta * linesPerClick / WHEEL_DELTA;
mouseWheelDelta %= Math.Max(1, WHEEL_DELTA / linesPerClick);
return scrollDistance;
}
public void Scroll(ScrollBar scrollBar, MouseEventArgs e)
{
int newvalue = scrollBar.Value - GetScrollAmount(e) * scrollBar.SmallChange;
scrollBar.Value = Math.Max(scrollBar.Minimum, Math.Min(scrollBar.Maximum - scrollBar.LargeChange + 1, newvalue));
}
}
}