Program.cs 1008 B

12345678910111213141516171819202122232425262728293031323334
  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 movesSubscription = moves.Subscribe(pos => Console.WriteLine("Mouse at: " + pos));
  21. var inputSubscription = input.Subscribe(inp => Console.WriteLine("User wrote: " + inp));
  22. using (new CompositeDisposable(movesSubscription, inputSubscription))
  23. {
  24. Application.Run(frm);
  25. }
  26. }
  27. }
  28. }