我做了一个文本框。怎么锁定,输入法,只让用户输入123456789,不能输入其它 的
解决方案 »
- 怎么用递归绑定数据
- 未将对象引用设置到对象的实例,如何解决?
- 如何将string类型的数字加入到float类型的SQL中
- 菜鸟问:treamWriter写文件的问题__在线等,100分。分不够再开贴另加。
- 多标签浏览器,遇到页面有window.opener 新窗口有bug,求解决办法
- 最近打算上一台服务器,园子里有要合租的吗
- 如何设置dataGrid
- 解决.net和水晶报表打包的极佳工具:InstallShield Developer v8.02 免费版 [五星]
- 怎么实现这样的程序阿?
- 只知道一个.h文件,怎么在C#中使用
- C#中从DataGridView中筛选数据的问题
- WinCE5.0 在VS2005(C#) RasDial 进行GPRS拨号成功后,已自动获得IP,但无法使用socket连接
Regex r = new Regex("^[0-9]{1,}$");
if(!r.IsMatch(textBox1.Text))
{
Messagebox.Show("请输入数字");
}
{
if ('0' > e.KeyChar || e.KeyChar > '9')//输入的按键值在‘0’~‘9’之间
{
if (e.KeyChar != 8)//不是backspace键
e.KeyChar = (char)0;//设定键值为0
}
Private Sub txt_BXPDJ02009_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
' 0キーから9キーまでと、BSキー以外の場合
If Not ((Strings.Asc("0") <= Strings.Asc(e.KeyChar) And Strings.Asc(e.KeyChar) <= Strings.Asc("9")) Or _
Strings.Asc(e.KeyChar) = 8 Or Strings.Asc(e.KeyChar) = Strings.Asc("-")) Then Messagebox.Show("请输入数字");
End If
end sub
{
if ((e.KeyValue >= 48 && e.KeyValue <= 57) || e.KeyValue == 8 || e.KeyValue == 46 || e.KeyValue == 190)
{
if (_FormatMode == FilterMode.Number)
{
if (e.KeyValue == 190)
{
isValidate = false;
isEnter = false;
}
else
{
isValidate = true;
isEnter = false;
}
}
else if (_FormatMode == FilterMode.NumberAndDot)
{
isValidate = true;
isEnter = false;
}
else
{
isValidate = false;
isEnter = false;
}
}
else if (e.KeyValue == 13)
{
isValidate = true;
isEnter = true; decimal tmp = Convert.ToDecimal(this.textBox.Text.Trim());
if (tmp <= _MinNumber)
tmp = _MinNumber;
else if (tmp >= _MaxNumber)
tmp = _MaxNumber; this.textBox.Text = tmp.ToString(_FormatString);
}
else
{
isValidate = false;
isEnter = false;
} base.OnKeyDown(e);
} private void textBox_KeyPress(object sender, KeyPressEventArgs e)
{
if (isValidate)
{
e.Handled = false;
}
else
e.Handled = true;
if (isEnter)
{
try
{
Convert.ToDecimal(this.textBox.Text.Trim());
}
catch
{
this.textBox.Text = "0";
} decimal tmp = Convert.ToDecimal(this.textBox.Text.Trim());
if (tmp <= _MinNumber)
tmp = _MinNumber;
else if (tmp >= _MaxNumber)
tmp = _MaxNumber; this.textBox.Text = tmp.ToString(_FormatString);
} base.OnKeyPress(e);
}