Note that there are some explanatory texts on larger screens.

plurals
  1. POHorizontal scroll using mouse wheel ( C# & WinAPI )
    primarykey
    data
    text
    <p>I am creating a logic to scrolling the control under mouse position without focus (outlook style) in my form. I am able to achieve this behavior using IMessageFilter. However I am facing difficulty to apply a Horizontal scroll, if "SHIFT" key is pressed. </p> <pre><code>using System; using System.ComponentModel; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices; using System.Drawing; public partial class UI : Form { MouseWheelMessageFilter mouseFilter = null; public UI() { InitializeComponent(); mouseFilter = new MouseWheelMessageFilter(); Application.AddMessageFilter(mouseFilter); this.FormClosed += (o, e) =&gt; Application.RemoveMessageFilter(mouseFilter); } } public class MouseWheelMessageFilter : IMessageFilter { [DllImport("user32.dll")] public static extern IntPtr WindowFromPoint(Point pt); [DllImport("user32.dll")] public static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wp, IntPtr lp); public const int MK_CONTROL = 0x0008; public const int MK_SHIFT = 0x0004; public const int WM_MOUSEWHEEL = 0x020A; public const int WM_MOUSEHWHEEL = 0x020E; public bool PreFilterMessage(ref Message m) { if (m.Msg == WM_MOUSEWHEEL) { var shiftKeyDown = (char)((Keys)m.WParam) == MK_SHIFT; //apply the scroll to the control at mouse location Point pos = new Point(m.LParam.ToInt32() &amp; 0xffff, m.LParam.ToInt32() &gt;&gt; 16); IntPtr hWnd = WindowFromPoint(pos); if (hWnd != IntPtr.Zero &amp;&amp; hWnd != m.HWnd &amp;&amp; Control.FromHandle(hWnd) != null) { if (shiftKeyDown) //TODO: Horizontal scroll - Not working WM_MOUSEHWHEEL (0x020E) //SendMessage(hWnd, WM_MOUSEHWHEEL, m.WParam, m.LParam); else //Vertical Scroll - working SendMessage(hWnd, WM_MOUSEWHEEL, m.WParam, m.LParam); return true; } } return false; } } </code></pre> <p>What should I need to do in the //TODO section to get horizontal scroll working?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload