简体   繁体   English

wpf-notifyIcon-鼠标事件-识别鼠标按钮

[英]wpf - notifyIcon - mouse event - identify mouse button

I use the notifyIcon from Winforms in a WPF application. 我在WPF应用程序中使用Winforms中的notifyIcon。 Bellow is part of my event handler: 贝娄是我的事件处理程序的一部分:

private void notifyIcon_Logger_MouseDown( object sender, EventArgs e )
{
        var st = e.ToString();
...

I may not make e parameter a MouseEventArgs because compiler says it does not match. 我可能不会使e参数成为MouseEventArgs,因为编译器说它不匹配。 But even so, I see that st is "System.Windows.Forms.MouseEventArgs". 但是即使如此,我仍然看到st是“ System.Windows.Forms.MouseEventArgs”。 How is that?! 那个怎么样?!

I have pinned e on IDE surface to watch it for debug purposes and I see it has a member Button. 我将e钉在IDE表面上以进行调试,以查看它的状态,我看到它具有一个Button成员。 I see something like 我看到类似的东西

Button = Right

but if I try e.Button I get error CS1061: 'EventArgs' does not contain a definition for 'Button' How is all these possible? 但是,如果我尝试使用e.Button,则会收到错误CS1061:'EventArgs'不包含'Button'的定义这些怎么可能? More importantly, how to identify mouse button? 更重要的是,如何识别鼠标按键?

mixing WPF and Winforms can sometimes be tricky... 混合使用WPF和Winforms有时会很棘手...

There are 2 types called MouseEventArgs. 有2种类型称为MouseEventArgs。 One is the WPF version in the System.Windows.Input namespace and the other is the Winforms version in the System.Windows.Forms namespace. 一个是System.Windows.Input命名空间中的WPF版本,另一个是System.Windows.Forms命名空间中的Winforms版本。

By simply casting it as MouseEventArgs the compiler uses the WPF form since this is WPF app but you need the Winforms version since this particular callback is for a Winforms control. 通过简单地将其转换为MouseEventArgs,编译器将使用WPF表单,因为这是WPF应用程序,但是您需要Winforms版本,因为此特定的回调用于Winforms控件。 So simply qualify it with the correct namespace in the callback definition... 因此,只需在回调定义中使用正确的名称空间对其进行限定...

private void notifyIcon_Logger_MouseDown( object sender, System.Windows.Forms.MouseEventArgs e )
{
        var st = e.ToString();
...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM