Program.cs 808 B

1234567891011121314151617181920212223242526272829303132
  1. using System;
  2. using System.Reactive.Linq;
  3. using System.Windows.Forms;
  4. using System.Reactive.Disposables;
  5. namespace Excercise6
  6. {
  7. class Program
  8. {
  9. static void Main()
  10. {
  11. var txt = new TextBox();
  12. var lbl = new Label { Left = txt.Width + 20 };
  13. var frm = new Form()
  14. {
  15. Controls = { txt, lbl }
  16. };
  17. var input = (from evt in Observable.FromEventPattern(txt, "TextChanged")
  18. select ((TextBox)evt.Sender).Text)
  19. .Throttle(TimeSpan.FromSeconds(1))
  20. .DistinctUntilChanged();
  21. using (input.ObserveOn(lbl).Subscribe(inp => lbl.Text = inp))
  22. {
  23. Application.Run(frm);
  24. }
  25. }
  26. }
  27. }