能不火的C#Windows窗体鼠标滚轮事件 [英] Can't fire MouseWheel event in C# Windows Forms

查看:425
本文介绍了能不火的C#Windows窗体鼠标滚轮事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,是不是在Visual Studio 2008中的活动窗格中这是很烦人列出的鼠标滚轮事件。

First off, the mousewheel event is not listed in Visual Studio 2008's events pane which is very annoying.

我找到了正确的格式在网上,虽然,写了这个我的代码:

I found the correct format online though, and wrote this into my code:

    private void Form1_MouseWheel(object sender, MouseEventArgs e)
    {
        Debug.WriteLine("Foo");
    }



...我从中没有得到响应时,鼠标滚轮旋转

...from which I'm getting no response when the mousewheel is rotated.

我在做这在我的代码的主类区域,设计师只包含一个窗体/窗/不管所以鼠标没有失去焦点。

I'm doing this in my code's main class area, and the designer contains only the one form/window/whatever so the mouse isn't losing focus.

namespace BlahBlah
{
    public partial class Form1 : Form
    {

和相比之下,我有这个方法正确的鼠标滚轮一个在上面,它工作得很好:

And by contrast, I have this method right above the mousewheel one and it works fine:

    private void Form1_MouseClick(object sender, MouseEventArgs e)
    {
        Debug.WriteLine("Foo");
    }

如果我猜的话,我想我没有正确连接代码的形式(又名:所有的东西,视觉工作室会为我做,如果我加入经过设计师的事件面板此事件)。但我可能是错的,或只是进行一些愚蠢的错误。

If I had to guess, I'm thinking I'm not correctly linking the code to the form (aka: all the stuff that visual studio would do for me if I added this event through the designer's events panel). But I could be wrong or just be making some silly error.

您能帮我得到任何一种反应,当鼠标滚轮旋转?谢谢!

Can you help me get ANY kind of response when the mouse wheel is rotated? Thanks!

推荐答案

鼠标滚轮事件需要进行设置。

The mousewheel event needs to be set up.

这个添加到Form1的构造函数(后InitalizeComponents();)

Add this to Form1's constructor (After InitalizeComponents();)

this.MouseWheel+= new MouseEventHandler(Form1_MouseWheel);

这篇关于能不火的C#Windows窗体鼠标滚轮事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆