Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Windows.Forms;
- using System.Reactive.Linq;
- using System.Drawing;
- using System.Threading;
- namespace rxforms
- {
- public class MainForm: Form
- {
- public MainForm ()
- {
- InitializeComponent ();
- }
- private void Reactive (string msg)
- {
- var mousemove = Observable.FromEventPattern<MouseEventArgs> (this, "MouseMove");
- var message = msg.ToCharArray ();
- for (int i = 0; i < message.Length; i++) {
- var l = new Label () {
- Text = message [i].ToString (),
- AutoSize = true,
- TextAlign = ContentAlignment.MiddleCenter
- };
- int closure = i;
- mousemove
- .Delay (TimeSpan.FromSeconds (0.07 * i)).ObserveOn(SynchronizationContext.Current)
- .Subscribe(e => {
- var left=l.Left = e.EventArgs.X + closure * 12 - 5;
- var top = e.EventArgs.Y + 15;
- l.Left = left;
- l.Top = top;
- });
- Controls.Add (l);
- }
- }
- private System.ComponentModel.IContainer components = null;
- /// <summary>
- /// Clean up any resources being used.
- /// </summary>
- /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
- protected override void Dispose (bool disposing)
- {
- if (disposing && (components != null)) {
- components.Dispose ();
- }
- base.Dispose (disposing);
- }
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- private void InitializeComponent ()
- {
- this.SuspendLayout();
- //
- // MainForm
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(646, 430);
- this.Name = "MainForm";
- this.Text = "RX test";
- this.Load += new System.EventHandler(this.MainForm_Load);
- this.ResumeLayout(false);
- }
- private void MainForm_Load(object sender, EventArgs e)
- {
- Reactive("Time flies like an arrow.");
- }
- }
- class MainClass
- {
- [STAThread]
- public static void Main(string[] args)
- {
- MainForm form = new MainForm();
- Application.Run(form);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment