知识清单
- 同类型按钮事件的利用和技巧
- 输入框掩码元素与规则使用
- 掩码框事件的开发 MaskInputRejected事件
- 信息提示框的开发利用
maskedTextBox 掩码控件 <==> 相当于 textBox(加强版)控件
掩码规则
会直接限制输入的结果,只能输入指定的规则的字符
0表示0 ~ 9
A表示字母数字
L只表示字母
< 转换为小写,将后续所有字符都转换为小写转换为大写,将后续所有字符都转换为大写
AsciiOnly 表示只能输入Ascii字符
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-HXFS9zYd-1661242092174)(/img/100.png)]
同类型按钮事件的利用和技巧
- 要有同类型控件
- 将同类型控件选择相同的事件
- 通过事件的 sender 这个 object 类型强制转为指定的控件类型
- 通过转换过来的控件直接调用某个属性或方法
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
//两种写法均可
RadioButton radioButton = sender as RadioButton;
RadioButton radioButton = (RadioButton)sender;
if (radioButton.Text == "身份证")
{
maskedTextBox1.Mask =
}
else if(radioButton.Text == "手机号")
{
}
else if (radioButton.Text == "日期时间")
{
}
else if (radioButton.Text == "自动转为大写")
{
}
}
掩码事件开发
- MaskInputRejected事件
- 使用 参数 e 来表示输入的位置情况 e.Position
else if (e.Position == maskedTextBox1.Mask.Length)
{
toolTip1.ToolTipTitle = "Sun提醒";
toolTip1.Show("已经在最后一个位置,请调", maskedTextBox1);
}
信息提示框的开发利用
- 使用 toolTip 来显示提示信息
- 设置提醒标题 使用 toolTip.ToolTipTitle = “”;
- 设置提醒内容到指定控件 使用 toolTip.Show(“”,控件);
//注意: 这里利用了鼠标的特性,鼠标必须在控件相关位置才能显示提示信息
toolTip1.Show("提醒内容", maskedTextBox);