Inference And Contravariance for Button Click, KeyPress, and MouseClick : Event System « GUI Windows Forms « C# / CSharp Tutorial






using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.ComponentModel;

    class InferenceAndContravariance
    {
        static void LogPlainEvent(object sender, EventArgs e)
        {
            Console.WriteLine ("An event occurred");
        }

        static void Main()
        {
            Button button = new Button();
            button.Text = "Click me";
            button.Click += LogPlainEvent;
            button.KeyPress += LogPlainEvent;
            button.MouseClick += LogPlainEvent;

            Form form = new Form();
            form.AutoSize = true;
            form.Controls.Add(button);
            Application.Run(form);
        }
    }








23.63.Event System
23.63.1.Use .Net event system
23.63.2.Inference And Contravariance for Button Click, KeyPress, and MouseClick