[英]wpf - notifyIcon - mouse event - identify mouse button
我在WPF应用程序中使用Winforms中的notifyIcon。 贝娄是我的事件处理程序的一部分:
private void notifyIcon_Logger_MouseDown( object sender, EventArgs e )
{
var st = e.ToString();
...
我可能不会使e参数成为MouseEventArgs,因为编译器说它不匹配。 但是即使如此,我仍然看到st是“ System.Windows.Forms.MouseEventArgs”。 那个怎么样?!
我将e钉在IDE表面上以进行调试,以查看它的状态,我看到它具有一个Button成员。 我看到类似的东西
Button = Right
但是,如果我尝试使用e.Button,则会收到错误CS1061:'EventArgs'不包含'Button'的定义这些怎么可能? 更重要的是,如何识别鼠标按键?
混合使用WPF和Winforms有时会很棘手...
有2种类型称为MouseEventArgs。 一个是System.Windows.Input命名空间中的WPF版本,另一个是System.Windows.Forms命名空间中的Winforms版本。
通过简单地将其转换为MouseEventArgs,编译器将使用WPF表单,因为这是WPF应用程序,但是您需要Winforms版本,因为此特定的回调用于Winforms控件。 因此,只需在回调定义中使用正确的名称空间对其进行限定...
private void notifyIcon_Logger_MouseDown( object sender, System.Windows.Forms.MouseEventArgs e )
{
var st = e.ToString();
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.