验证用户输入
字段级验证
TextBox控件
MaxLength 输入字符个数
PasswordChar 用某字符代替用户输入
ReadOnly 只读
MultiLine 是否允许多行输入
事件
KeyDown
KeyPress 当按下具有相应ASCII值的键时,(只按下Ctrl,Alt,功能键时不能引发)
KeyUp
事件参数 System.Windows.Forms.KeyEventArgs e
参数属性
Alt Alt键是否按下
KeyCode 按键代码
验证字符
Char.IsDigit
Char.IsLetter
Char.IsLetterOrDigit
Char.IsPunctuation
Char.IsLower
Char.IsUpper
例:Char.IsDigit(e.KeyChar)==true
处理焦点
if (textBox1.CanFocus == true) textBoxq.Focus();
焦点事件
Enter 获得焦点
GotFocus 首次获得焦点
Leave 离开焦点
LostFocus 首次离开焦点
Validating 丢失焦点之前。 可设置CancelEventArgs e 的Cancel属性为true,取消焦点丢失
Validated
需设置CausesValidation=true
TextBox控件
MaxLength 输入字符个数
PasswordChar 用某字符代替用户输入
ReadOnly 只读
MultiLine 是否允许多行输入
事件
KeyDown
KeyPress 当按下具有相应ASCII值的键时,(只按下Ctrl,Alt,功能键时不能引发)
KeyUp
事件参数 System.Windows.Forms.KeyEventArgs e
参数属性
Alt Alt键是否按下
KeyCode 按键代码
验证字符
Char.IsDigit
Char.IsLetter
Char.IsLetterOrDigit
Char.IsPunctuation
Char.IsLower
Char.IsUpper
例:Char.IsDigit(e.KeyChar)==true
处理焦点
if (textBox1.CanFocus == true) textBoxq.Focus();
焦点事件
Enter 获得焦点
GotFocus 首次获得焦点
Leave 离开焦点
LostFocus 首次离开焦点
Validating 丢失焦点之前。 可设置CancelEventArgs e 的Cancel属性为true,取消焦点丢失
Validated
需设置CausesValidation=true