MouseWheel Not Working

I saw in a newsgroup a problem where mousewheel wasnt working on a panel and the issue is because the form isnt passing the event on to its children. I wrote the code below which when pasted into a form. Makes it pass on the event so controls on the form get notified of the MouseWheel event.
bool sendingMessage = false;
  protected override void WndProc(ref Message m)
   Point mp = MousePosition;
   if (m.Msg == 522)
    if (sendingMessage)
    m.Result = (IntPtr)0;
    Debug.Print("Mouse Wheel: lparam = {0},WParam = {1}, Result ={2}", m.LParam, m.WParam, m.Result);
     sendingMessage = true;
    SendMessage(GetChildAtPoint(PointToClient(mp)).Handle,     m.Msg, m.WParam.ToInt32(), m.LParam.ToString());
    sendingMessage = false;
    }catch(Exception exception){
   m.Result = (IntPtr)0;
   base.WndProc(ref m);
public static extern int SendMessage(IntPtr hwnd, [MarshalAs(UnmanagedType.U4)] int Msg, int wParam, [MarshalAsSystem.Runtime.InteropServices.UnmanagedType.LPStr)] string lParam);
Hope it helps someone
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s