我想问的是在textBox框中输入非0-9数字时,textBox自动忽略掉,
例如说我在输入123后再按个K进去,但不充许K显示,怎么搞?
例如说我在输入123后再按个K进去,但不充许K显示,怎么搞?
解决方案 »
- 求C#阴历转阳历的类
- 求C#中office2007样式的控件!
- 用代码动态生成固定格式的DataGridView控件
- 求判断String长度是否春在某些数字
- 我想让C++写的DLL能直接被C#程序引用,为什么会报LNK2028错
- 请教:我用DataTable.PrimaryKey属性为啥不能获取表的主键?
- ^^^^^^^^^^^^^^^^^^^^80分求用Jmail组件,发送接收邮件的实例!!找了1个月了^^^^^^^^^^^^
- 帮我看一下, if (num < 0)的异常怎么写
- 关于vs进行asp.net开发中的一些问题?
- WinForm数据绑定
- 如何从一个窗口获取另一个窗口里面的公共变量值!
- c# word操作问题
{
if (e.KeyChar < '0' || e.KeyChar > '9')
{
e.Handled = true;
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
textBox1.Text = System .Text .RegularExpressions.Regex.Replace(textBox1.Text, @"[^0-9\.]", "");
}另参考
http://community.csdn.net/Expert/topic/5386/5386616.xml?temp=.9118158
1、在 Microsoft Visual Studio .NET 的“文件”菜单上,单击“新建”,然后单击“项目”。
2、在“新建项目”对话框中,选择“Visual C#项目”,再选择“Windows 应用程序”模板。
3、键入 TextApp 作为该程序的名称,然后单击确定。
4、在Form1.cs的视图设计器中,添加如下控件:
控件类型 控件名称 控件属性 属性值
Label label1 Text 输入十进制数
Label label2 Text 输入大写字母
TextBox textBox1
TextBox textBox2
5、在Form1.cs的视图设计器中,选中textBox1,在属性框中选中事件,双击KeyPress,在Form1.cs的代码设计器中,添加修改如下代码
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (Char.IsNumber(e.KeyChar) || (Keys)e.KeyChar == Keys.Back || e.KeyChar.ToString() == ".")
e.Handled = false;//允许输入
else
e.Handled = true;//取消输入
}
6、在Form1.cs的视图设计器中,选中textBox2,在属性框中选中事件,双击KeyPress,在Form1.cs的代码设计器中,添加修改如下代码
private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
{
if (Char.IsUpper(e.KeyChar) || (Keys)e.KeyChar == Keys.Back)
e.Handled = false;//允许输入
else
e.Handled = true;//取消输入
}
7、编译
要想轻松开发软件,详见http://www.psec.net.cn