xiacy

导航

5.2.1 委托参数的逆变性

static void LogPlainEvent(object sender, EventArgs e)
        {
            Console.WriteLine("LogPlain");
        }

        static void LogKeyEvent(object sender, KeyPressEventArgs e)
        {
            Console.WriteLine("LogKey");
        }

        static void LogMouseEvent(object sender, MouseEventArgs e)
        {
            Console.WriteLine("LogMouse");
        }

        static void Main(string[] args)
        {
            Button button1 = new Button();
            button1.Text = "Click me";
            button1.Click+=LogPlainEvent;
            button1.KeyPress+=LogKeyEvent;
            button1 .MouseClick+=LogMouseEvent;

            Form form1 = new Form();
            form1.AutoSize = true;
            form1.Controls.Add(button1);
            Application.Run(form1);
        }

 

 

posted on 2012-05-01 22:12  xiacy  阅读(163)  评论(0编辑  收藏  举报