C#用继承实现自定义控件 让控件默认绑定一个事件
public class myText : TextBox { public myText() { this.Enter += new System.EventHandler(txt_Enter); this.Leave += new System.EventHandler(txt_Leave); } private void txt_Enter(object sender, EventArgs e) { this.BackColor = Color.FromArgb(255, 210, 253, 208); } private void txt_Leave(object sender, EventArgs e) { this.BackColor = Color.FromArgb(255, 255, 255, 255); } }
这样就直接在窗体加载的时候给文本框绑定事件了