textbox只允许输入指定数字(1-7),并且不能重复
在KeyPress事件中实现
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; } }