82 //在这个例子中我们不想取消further processing 83 //但是如果我们想要这么做的话,我们只需要添加以下一行: 84 //e.Cancel=true; 85 } 86 else 87 { 88 this.BackColor = SystemColors.Window; 89 tb.Tag = true; 90 } 91 //Finally ,we call ValidateOK which will set the value of the OK button. 92 ValidateOK(); 93 } 94 95 private void textBoxAge_KeyPress(object sender, KeyPressEventArgs e) 96 { 97 if ((e.KeyChar < 48 e.KeyChar > 57) && e.KeyChar != 8) 98 { 99 e.Handled = true; //Remove the character 100 //等于true告诉用户不应该对字符进行任何操作 101 } 102 } 103 104 private void textBox_TextChanged(object sender, EventArgs e) 105 { 106 //Cast the sender object to a TextBox 107 TextBox tb = (TextBox)sender; 108 109 //Test if the data is valid and set the tag and back ground color accordingly.