如何在timertick中使用MouseEventArgs [英] How use MouseEventArgs in timertick

查看:81
本文介绍了如何在timertick中使用MouseEventArgs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private void timer1_Tick(object sender, EventArgs e){

       MouseEventArgs m=e as MouseEventArgs;
        if (m.Button == MouseButtons.Right)
        {
            MessageBox.Show("dfgdf");
        }
}





它不工作怎么办?



It dont work How can I do it ?

推荐答案

不,它不会工作。

EventArgs类不是MouseEventArrgs类的示例,而是反过来:MouseEventArgs派生自EventArgs。所以你可以把一个MouseEventArgs转换成一个EventArgs,但是你不能走另一条路,因为计算机无法发明所需的信息。



相反,使用控件.MouseButtons属性:

No, it won''t work.
The EventArgs class is not an example of a MouseEventArrgs class, rather the other way round: MouseEventArgs derives from EventArgs. So you can cast a MouseEventArgs ro an EventArgs, but you can''t go the other way because the computer cannot invent the required information.

Instead, use the Control.MouseButtons property:
MouseButtons mb = MouseButtons;
if (mb == MouseButtons.Right)
    {
    Console.WriteLine(mb);
    }


这篇关于如何在timertick中使用MouseEventArgs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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