All pastes #525968 Raw Edit

Stuff

public text v1 · immutable
#525968 ·published 2007-05-31 16:33 UTC
rendered paste body
using System;
using System.Windows.Forms;

class MyRedirecter : Control {
        Control dst;
        public MyRedirecter (string s, Control dst) {
                this.Name = s;
                this.dst = dst;
        }
        protected override void OnEnter (EventArgs e) {
                Console.WriteLine ("redirecter {0} entered", Name);
                //Console.WriteLine (Environment.StackTrace);
                base.OnEnter (e);
                dst.Focus();
        }
        protected override void OnLeave (EventArgs e) {
                Console.WriteLine ("redirecter {0} left", Name);
                base.OnLeave (e);
        }
}

class MyControl : Control {
        public MyControl (string s) { this.Name = s; }
        protected override void OnEnter (EventArgs e) {
                Console.WriteLine ("{0} entered", Name);
                //Console.WriteLine (Environment.StackTrace);
                base.OnEnter (e);
        }
        protected override void OnLeave (EventArgs e) {
                Console.WriteLine ("{0} left", Name);
                base.OnLeave (e);
        }
}

//       r1 ....+
//     /   \    |
//    c2    c1  |
//    ^       \ v
//    +........r2

class Test : Form {
        public Test ()
        {
                Control c1 = new MyControl ("c1");
                Control c2 = new MyControl ("c2");
                MyRedirecter r2 = new MyRedirecter ("r2", c2);
                MyRedirecter r1 = new MyRedirecter ("r1", r2);

                Controls.Add (r1);
                r1.Controls.Add (c1);
                c1.Controls.Add (r2);
                Controls.Add (c2);
        }

        public static void Main (string[] args) {
                Application.Run (new Test());
        }
}