使标签页不处理鼠标滚轮事件

使标签页不处理鼠标滚轮事件

本文介绍了使标签页不处理鼠标滚轮事件(C#)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个使用TabPages中的PictureBoxes的MDI(选项卡式)应用程序.图片框有时会比标签页大,因此会出现滚动条.它是使用Windows窗体以C#编写的.

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.

在我的标签页中,我捕获并处理了MouseWheel事件中的鼠标滚轮事件(我用它来旋转在图片框中绘制的某些对象).

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.

推荐答案

子类并重写WndProc()方法以忽略WM_MOUSEWHEEL消息:

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);
  }
}

然后使用您的MyTabPage子类代替标准TabPage.

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

这篇关于使标签页不处理鼠标滚轮事件(C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 06:33