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