using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ConsoleApp3
{
class Program
{
static void Main(string[] args)
{
Form form = new Form();//事件拥有者form
Controller controller = new Controller(form);
form.ShowDialog();
}
}
class Controller
{
private Form form;
public Controller(Form form)
{
if(form!=null)
{
this.form = form;
this.form.Click += this.FormClick;//事件Click,事件响应者Controller,事件处理器Controller的FormClick方法
}
}
private void FormClick(object sender, EventArgs e)
{
this.form.Text = DateTime.Now.ToString();
}
}
}
例子2