你应该用CvtInt32(textBox.text.trim());
判断成功否,解决问题了。
记着给我分。
判断成功否,解决问题了。
记着给我分。
解决方案 »
- c#.net datagridview值传到textbox修改,更新数据库,得根据主键ID来确定是否更新该记录
- Can't find PInvoke DLL 'hhpImgrSdk.dll'.
- c#调用DLL报错:attempted to read or write protected memory。急!急!急!
- C# 在一个循环中创建子线程,运行出错.
- 水晶报表问题
- TreeView+DataGrid 求助
- 怎样在按钮上添加图片?(在线等)
- 安装程序问题(高分)
- LostKeyboardFocus 触发的方法能否加额外的参数?
- 大侠们学习C#,.net framework,觉得那本书最好????
- 如何继承窗口
- 关于一个用户控件的问题
{
if(e.KeyCode < Keys.D0 || e.KeyCode > Keys.D9)
{
textBox1.ReadOnly = true;
textBox1.BackColor = SystemColors.Window;
}
}private void textBox1_KeyUp(object sender, KeyEventArgs e)
{
textBox1.ReadOnly = false;
}
再在文本框内添加如下一句,你喜欢别人只能输入什么字符都行!private void TextBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
e.Handled= adoconn.ValiText (e.KeyChar.ToString() ,"0123456789.",true ,this.TextBox1.Text.ToString().Trim() ,true);
}public static bool ValiText(string KeyIn,string ValidateString,bool Editable,string Txt,bool IsNum)
{
//通过 keypress 事件的 e.Handled= ValiText (e.KeyChar.ToString() ,"0123456789.",true ,txtedit0.Text ,true);
string Validatelist;
if ((Txt.IndexOf(".")>=0)&&(KeyIn==".")&&IsNum )
return true;
if (KeyIn=="-"&&Txt.Length >0 )
return true;
if (Editable)
Validatelist=ValidateString.ToUpper()+Convert.ToChar(8);
else
Validatelist=ValidateString.ToUpper() ; //转成大写
if (Validatelist.IndexOf(Convert.ToChar(KeyIn),0)<0 )
return true;
else
return false;
}
你可以 把form的属性KeyPreview设为true,这样在任何一个 form中的控件发生的键盘事件
都首先被 form 捕获,在 form 的 KeyDown 里面判定 按键 通常可以用 e.KeyCode 来判定按下的字符 ,如果非法字符可以通过使 e.Handle = false 来使控件忽略 键盘输入