input textbox only a specified number (1-7), and can not be repeated
Implemented in the KeyPress event
private void txtWeek_KeyPress(object sender, KeyPressEventArgs e) { if ((e.KeyChar < '1' || e.KeyChar > '7') && e.KeyChar != (char)8) //允许输入退格键 { e.Handled = true; } if (((TextBox)sender).Text.Trim().IndexOf(e.KeyChar)>=0) { e.Handled = true; } }