日期:2014-05-18 浏览次数:20918 次
private void textBox1_TextChanged(object sender, EventArgs e) { TextBox Tb = (TextBox)sender; if (textBox1.Text.Length == 0) { Tb.Tag = false; Tb.BackColor = Color.Yellow; } else { Tb.Tag = true; Tb.BackColor = SystemColors.Window; } } private void textBox1_Validating(object sender, CancelEventArgs e) { TextBox Tb = (TextBox)sender; if (textBox1.Text.Length == 0) { Tb.Tag = false; Tb.BackColor = Color.Yellow; } else { Tb.Tag = true; Tb.BackColor = SystemColors.Window; } }
private void button1_Click(object sender, EventArgs e) { this.textBox1.Validating -= new System.ComponentModel.CancelEventHandler(this.textBox1_Validating); this.textBox1.TextChanged -= new System.EventHandler(this.textBox1_TextChanged); this.Close(); }
------解决方案--------------------
是在属性设计器里面设置CausesValidation为False不是在Button的Click的代码里面~~~~~
我这边是可以的~~~