Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Mouse wheel events not firing  (Read 2583 times)

0 Members and 1 Guest are viewing this topic.

Merad

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Mouse wheel events not firing
« on: March 24, 2015, 07:09:05 pm »
I'm using the .NET bindings in a C# winforms app, and actually drawing onto a panel.  Mouse clicked events work fine, but scroll events never fire.

My setup code is simply

// windowHandle is the handle of the panel we're drawing to
m_renderWindow = new RenderWindow(windowHandle,
  new ContextSettings { AntialiasingLevel = 8 });
m_renderWindow.Resized += (sender, args) => UpdateViewSize();
m_renderWindow.MouseWheelMoved +=
  (sender, args) => Log.Info("mouse scrolled");
m_renderWindow.MouseButtonPressed +=
  (sender, args) => Log.Info("mouse clicked");

My main loop calls both System.Windows.Forms.Application.DoEvents() and m_renderWindow.DispatchEvents().  And as I said, clicks work fine...

Merad

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: Mouse wheel events not firing
« Reply #1 on: March 24, 2015, 08:10:24 pm »
I just checked, and the event does fire correctly when I allow SFML to create the window.  So presumably the problem is with mouse events being forwarded from the winforms panel to the renderwindow.  Any ideas?

Merad

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: Mouse wheel events not firing
« Reply #2 on: March 24, 2015, 08:55:29 pm »
Ok, I found the solution, in case anyone else runs into this.  Windows only sends mouse wheel events to the control that has focus, but Panel is not a focusable control by default.  There doesn't seem to be a way to easily change this, so I added the following in my Form's ctor to force the panel to focus when the mouse hovers over it

drawingPanel.MouseHover += (sender, args) => drawingPanel.Focus();

 

anything