Make tabpage not process mousewheel events (C#)

拜拜、爱过 提交于 2019-12-10 11:47:31

问题


I have made a MDI (tabbed) application that uses PictureBoxes inside TabPages. The picturebox is sometimes larger then the tabpage, so scrollbars appear. It is written in C# using Windows Forms.

Inside my tabpage, I capture and process mouse wheel events in the MouseWheel event (i use it to rotate some objects I draw in the picturebox).

But when I have the scrollbars, when I rotate the mouse wheel, my objects rotate, but the tabpage also scrolls down.

How can I make the tabpage not process the mousewheel event, and thus make it not scroll down? I want it to only be scrollable if the user clicks and drags on the scrollbar.


回答1:


Subclass TabPage and override the WndProc() method to ignore the WM_MOUSEWHEEL message:

public class MyTabPage : TabPage
{
  private const int WM_MOUSEWHEEL = 0x20a;

  protected override void WndProc(ref Message m)
  {
    // ignore WM_MOUSEWHEEL events
    if (m.Msg == WM_MOUSEWHEEL)
    {
      return;
    }

    base.WndProc(ref m);
  }
}

Then use your MyTabPage subclass in place of the standard TabPage.



来源:https://stackoverflow.com/questions/1351046/make-tabpage-not-process-mousewheel-events-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!