检测左键点击鼠标的Winform [英] Detecting a left button mouse click Winform

查看:222
本文介绍了检测左键点击鼠标的Winform的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要做的就是让我的winform显示调试行有史以来的时候我在WinForm的点击。然而,当我这样做,没有任何反应。我知道如何让一个按钮/其他点击事件发生。但我需要的是能够对我的winform内的任意位置单击。

What I'm trying to do is get my winform to display a debug line when ever I click in my winform. However, when I do, nothing happens. I know how to get a button / other click event to happen. But what I need is to be able to click anywhere within my winform.

我GOOGLE了本作的过去一小时,但不能看到我在做什么错。据我所知,这个代码应该是检测鼠标点击正确的。这种方法是举行withing的Form1.cs的类:

I've googled this for the past hour but can't see what I'm doing wrong. As far as I'm aware, this code should be correct in detecting a mouse click. This method is held withing the form1.cs class:

  private void mouseClick(object sender, MouseEventArgs e)
    {
        if (e.Button == MouseButtons.Left)
        {    
            Trace.WriteLine("Mouse clicked");
        }
    }



我试过设置刹车点,但这些别'吨得到任何触发。这是什么我做错了?

I've tried setting brake points, but these don't get triggered either. What is it I'm doing wrong?

很抱歉的愚蠢的新手问题,但我很新的WinForm的节目。

Sorry for the stupidly newbie question, but I am very new to winform programming.

推荐答案

如何添加事件处理程序:

How to add the EventHandler:

public Form1()
{
    InitializeComponent();
    // This line should you place in the InitializeComponent() method.
    this.MouseClick += mouseClick;
}

这篇关于检测左键点击鼠标的Winform的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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