Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8080245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:21:23+00:00 2026-06-05T16:21:23+00:00

In my C# 3.5 Windows Forms application, I have a few SplitContainers. There is

  • 0

In my C# 3.5 Windows Forms application, I have a few SplitContainers. There is a list control inside each (dock fill). When the focus is on one of these controls and I move mouse wheel, the list, which is now focused, is scrolled.

My task is to scroll the list, which is currently hovered by mouse, not the one which is selected. Is it possible in Windows Forms? If not, is it possible with PInvoke?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T16:21:25+00:00Added an answer on June 5, 2026 at 4:21 pm

    It looks like you can use the IMessageFilter and PInvoke to handle this. An example in VB can be found at Redirect Mouse Wheel Events to Unfocused Windows Forms Controls. You should be able to easily convert this to C#.

    Points of Interest

    This class uses the following techniques for the given task:

    • Listen to the control’s MouseEnter and MouseLeave events to determine when the mouse pointer is over the control.
    • Implement IMessageFilter to catch WM_MOUSEWHEEL messages in the application.
    • PInvoke the Windows API call SendMessage redirecting the WM_MOUSEWHEEL message to the control’s handle.
    • The IMessageFilter object is implemented as a singleton of the MouseWheelRedirector class and accessed by the shared members Attach, Detach, and Active.

    Using a VB.NET to C# converter, this is what you end up with:

    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Data;
    using System.Diagnostics;
    
    using System.Windows.Forms;
    using System.Runtime.InteropServices;
    
    public class MouseWheelRedirector : IMessageFilter
    {
        private static MouseWheelRedirector instance = null;
        private static bool _active = false;
        public static bool Active
        {
           get { return _active; }
           set
           { 
              if (_active != value) 
              {
                 _active = value;
                 if (_active)
                 {
                    if (instance == null)
                    {
                        instance = new MouseWheelRedirector();
                    }
                    Application.AddMessageFilter(instance);
                 }
                 else
                 {
                    if (instance != null)
                    {
                       Application.RemoveMessageFilter(instance);
                    }
                 }
              }
           }
        }
    
        public static void Attach(Control control)
        {
           if (!_active)
              Active = true;
           control.MouseEnter += instance.ControlMouseEnter;
           control.MouseLeave += instance.ControlMouseLeaveOrDisposed;
           control.Disposed += instance.ControlMouseLeaveOrDisposed;
        }
    
        public static void Detach(Control control)
        {
           if (instance == null)
              return;
           control.MouseEnter -= instance.ControlMouseEnter;
           control.MouseLeave -= instance.ControlMouseLeaveOrDisposed;
           control.Disposed -= instance.ControlMouseLeaveOrDisposed;
           if (object.ReferenceEquals(instance.currentControl, control))
              instance.currentControl = null;
        }
    
        private MouseWheelRedirector()
        {
        }
    
    
        private Control currentControl;
        private void ControlMouseEnter(object sender, System.EventArgs e)
        {
           var control = (Control)sender;
           if (!control.Focused)
           {
              currentControl = control;
           }
           else
           {
              currentControl = null;
           }
        }
    
        private void ControlMouseLeaveOrDisposed(object sender, System.EventArgs e)
        {
           if (object.ReferenceEquals(currentControl, sender))
           {
              currentControl = null;
           }
        }
    
        private const int WM_MOUSEWHEEL = 0x20a;
        public bool PreFilterMessage(ref System.Windows.Forms.Message m)
        {
           if (currentControl != null && m.Msg == WM_MOUSEWHEEL)
           {
              SendMessage(currentControl.Handle, m.Msg, m.WParam, m.LParam);
              return true;
           }
           else
           {
              return false;
           }
        }
    
        [DllImport("user32.dll", SetLastError = false)]
        private static extern IntPtr SendMessage(
           IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Scenario I have a Windows Forms Application. Inside the main form there is a
I have a windows forms application in .NET 3.5. There's one form with 20
I have a Windows Forms application in C# .NET. It contains a user-drawn control
I'm building a Windows Forms application where I have a menuStrip and a toolStripMenuItem
I have an application developed in C++ in Visual Studio 2003 (Windows Forms application).
Scenario I have a windows forms application. I want to use two different WCF
I have a C# Windows Forms application, whose prototype was created on SQL Server
I have a windows forms application that reads and updates an XML file with
I have a Windows Forms application that on it I have a RichTextBox, like
I have multiple business entities in VB.NET Windows Forms application. Right now they are

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.