mirror of
https://github.com/colhountech/DarkUI.Net5.git
synced 2025-07-01 22:59:27 +03:00
Added ControlScrollFilter
ControlScrollFilter can be added to the application's message filter list to re-route all mousewheel events to the control the user is current hovering over with their cursor.
This commit is contained in:
parent
6d794dcb52
commit
71105b8e77
@ -124,9 +124,12 @@
|
||||
<DesignTime>True</DesignTime>
|
||||
<DependentUpon>TreeViewIcons.resx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Win32\ControlScrollFilter.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Renderers\DarkMenuRenderer.cs" />
|
||||
<Compile Include="Renderers\DarkToolStripRenderer.cs" />
|
||||
<Compile Include="Win32\Native.cs" />
|
||||
<Compile Include="Win32\WindowsMessages.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Forms\DarkDialog.resx">
|
||||
|
27
DarkUI/Win32/ControlScrollFilter.cs
Normal file
27
DarkUI/Win32/ControlScrollFilter.cs
Normal file
@ -0,0 +1,27 @@
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace DarkUI
|
||||
{
|
||||
public class ControlScrollFilter : IMessageFilter
|
||||
{
|
||||
public bool PreFilterMessage(ref Message m)
|
||||
{
|
||||
switch (m.Msg)
|
||||
{
|
||||
case (int)WM.MOUSEWHEEL:
|
||||
case (int)WM.MOUSEHWHEEL:
|
||||
var hControlUnderMouse = Native.WindowFromPoint(new Point((int)m.LParam));
|
||||
|
||||
if (hControlUnderMouse == m.HWnd)
|
||||
return false; // Already headed for the right control.
|
||||
|
||||
// Redirect the message to the control under the mouse.
|
||||
Native.SendMessage(hControlUnderMouse, (uint)m.Msg, m.WParam, m.LParam);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
15
DarkUI/Win32/Native.cs
Normal file
15
DarkUI/Win32/Native.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace DarkUI
|
||||
{
|
||||
public sealed class Native
|
||||
{
|
||||
[DllImport("user32.dll")]
|
||||
public static extern IntPtr WindowFromPoint(Point point);
|
||||
|
||||
[DllImport("user32.dll", CharSet = CharSet.Auto)]
|
||||
public static extern IntPtr SendMessage(IntPtr hWnd, UInt32 msg, IntPtr wParam, IntPtr lParam);
|
||||
}
|
||||
}
|
1199
DarkUI/Win32/WindowsMessages.cs
Normal file
1199
DarkUI/Win32/WindowsMessages.cs
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,4 +1,5 @@
|
||||
using DarkUI;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Example
|
||||
{
|
||||
@ -8,6 +9,10 @@ namespace Example
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
// Add the control scroll message filter to re-route all mousewheel events
|
||||
// to the control the user is currently hovering over with their cursor.
|
||||
Application.AddMessageFilter(new ControlScrollFilter());
|
||||
|
||||
// Build dummy list data
|
||||
for (var i = 0; i < 100; i++)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user