Program.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using System;
  2. using System.Reactive.Linq;
  3. using System.Windows.Forms;
  4. using System.Reactive.Disposables;
  5. namespace Excercise4
  6. {
  7. class Program
  8. {
  9. static void Main()
  10. {
  11. var txt = new TextBox();
  12. var frm = new Form()
  13. {
  14. Controls = { txt }
  15. };
  16. var moves = from evt in Observable.FromEventPattern<MouseEventArgs>(frm, "MouseMove")
  17. select evt.EventArgs.Location;
  18. var input = from evt in Observable.FromEventPattern(txt, "TextChanged")
  19. select ((TextBox)evt.Sender).Text;
  20. var overFirstBisector = from pos in moves
  21. where pos.X == pos.Y
  22. select pos;
  23. var movesSubscription = overFirstBisector.Subscribe(pos => Console.WriteLine("Mouse at: " + pos));
  24. var inputSubscription = input.Subscribe(inp => Console.WriteLine("User wrote: " + inp));
  25. using (new CompositeDisposable(movesSubscription, inputSubscription))
  26. {
  27. Application.Run(frm);
  28. }
  29. }
  30. }
  31. }