鼠标左键单击在事件上使用 Reactive 扩展 IObservable 在 winform 上检测 [英] Left mouse button click detect on winform using Reactive extensions IObservable on events

查看:53
本文介绍了鼠标左键单击在事件上使用 Reactive 扩展 IObservable 在 winform 上检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

刚开始阅读 Reactive 扩展.我正在尝试在我的 winform 上观看一个简单的鼠标左键单击.意思是任何有点击的地方(在表单上的任何控件上,包括表单)我只想显示一条消息检测到点击".到目前为止,我有

Just started reading on Reactive extensions. I am trying to watch a simple left mouse button click on my winform. Meaning anywhere there is a click (on any control on the form including the form) I just want to display a message "Click detected". So far I have

var mouseDown = Observable.FromEvent<MouseButtonEventArgs>(frmMain, "MouseDown");
//missing code please fill here 
mouseDown.Subscribe(() => Debug.WriteLine("left click detected.");

我知道第一行会检测任何鼠标事件.我只想单击鼠标左键.请发布工作代码,以便我可以更好地理解这一点.现在,我从未使用过像 .takeuntil 等流行语.进一步完善我的问题.

I know the first line will detect any mouse event. I want just the left mouse button click. Please post working code so I can understand this better. Right now in a tailspin with buzzwords I have never used before like .takeuntil etc.. Further refining my question. What is the Rx equivalent of

protected override void WndProc(ref Message m)
{
    Console.Writeline("{0}", m.Msg);
}

那应该观察每个可观察的鼠标或键盘事件.谢谢

That should observe every observable mouse or keyboard event. thank you

推荐答案

抱歉,我不确定这是否是有效代码(现在无法尝试),但它应该可以帮助您入门.

Sorry, I'm not sure if thats working code (can't try it now) but it should get you started.

var mouseDown = Observable.FromEvent<MouseButtonEventArgs>(frmMain, "MouseDown")
                      .Where(x => x.LeftButton == MouseButtonState.Pressed);

mouseDown.Subscribe(() => Debug.WriteLine("left click detected.");

这篇关于鼠标左键单击在事件上使用 Reactive 扩展 IObservable 在 winform 上检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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