private void button1_Click(object sender, EventArgs e) { //获取用户输入 //把信息保存在一个UCEventArgs对象中 UCEventArgs uce = new UCEventArgs(); uce.UserName = textBox1.Text; uce.UserPassword = textBox2.Text; uce.IsPass = false; //并触发事件方法 if (login != null) { login(this, uce); //把控件对象和控件信息传入事件储存的方法中 //而方法是由使用这个控件的地方写的 //所以要注意这里的this与uce不是给login,而是给那个方法 //登入成功还是失败造成的现象可以在内部和外部写 //if (uce.IsPass == true) //{ // this.BackColor = Color.Red; //} //else //{ // this.BackColor = Color.Blue; //} } }
void ucLoginControl1_login(object arg1, UCEventArgs arg2) { if (arg2.UserName == "admin" && arg2.UserPassword == "123456") { //arg2.IsPass = true; UCLoginControl LC = (UCLoginControl)arg1; LC.BackColor = Color.Red; } else { UCLoginControl LC = (UCLoginControl)arg1; LC.BackColor = Color.Blue; } }