1
0

Program.cs 1.0 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 = Observable.FromEventPattern<MouseEventArgs>(frm, "MouseMove");
  17. var input = Observable.FromEventPattern<EventArgs>(txt, "TextChanged");
  18. var moveSubscription = moves.Subscribe(evt =>
  19. {
  20. Console.WriteLine("Mouse at: " + evt.EventArgs.Location);
  21. });
  22. var inputSubscription = input.Subscribe(evt =>
  23. {
  24. Console.WriteLine("User wrote: " + ((TextBox)evt.Sender).Text);
  25. });
  26. using (new CompositeDisposable(moveSubscription, inputSubscription))
  27. {
  28. Application.Run(frm);
  29. }
  30. }
  31. }
  32. }