//1、在窗口初始化时添加事件委托
private void LoginFrm_Load(object sender, EventArgs e)
{
txt_username.GotFocus += new EventHandler(txt_username_GotFocus);
txt_username.LostFocus += new EventHandler(txt_username_LostFocus);
}
//2、手写像事件方法一样的方法
private void txt_username_GotFocus(object sender, EventArgs e)
{
//获得焦点要执行的代码
}
private void txt_pwd_GotFocus(object sender, EventArgs e)
{
//失去焦点要执行的代码
}