开发者

Left mouse button click detect on winform using Reactive extensions IObservable on events

开发者 https://www.devze.com 2023-03-12 00:28 出处:网络
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 ju

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.");

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.");
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号