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);
        }
    }

这样就直接在窗体加载的时候给文本框绑定事件了

posted @ 2012-12-25 15:23  下-个路口  阅读(1020)  评论(0编辑  收藏  举报