xiacy

导航

5.1.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+=new EventHandler(LogPlainEvent);
            button1.KeyPress+=new KeyPressEventHandler(LogKeyEvent);
            button1 .MouseClick+=new MouseEventHandler(LogMouseEvent);

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

 

posted on 2012-05-01 21:55  xiacy  阅读(159)  评论(0编辑  收藏  举报