void loginForm1_LoginDelegate(object sender, MyEventArgs e) { if (e.LoginName == "admin" && e.LoginPwd == "123456") { e.Result = true; } }
private void btnLogin_Click(object sender, EventArgs e) { MyEventArgs myEventArgs = new MyEventArgs(); myEventArgs.LoginName = this.txtName.Text; myEventArgs.LoginPwd = this.txtPwd.Text; myEventArgs.Result = false; //this指的是btnLogin这个控件 LoginDelegate(this, myEventArgs); if (myEventArgs.Result) { this.txtName.BackColor = Color.Green; this.txtPwd.BackColor = Color.Green; } else { this.txtName.BackColor = Color.Red; this.txtPwd.BackColor = Color.Red; } }