关于 TextBox 框的问题

chen51630 2006-11-02 11:35:49
问题1:如何控制TextBox框在输入数据的时候只能输入数字,不能输入文本!!

问题2:在TextBox 框的多行输入里,如何去分别读取每一行的数据给不同的变量!!

希望大家会的能够帮帮忙,谢谢你们的支持!!!!
...全文
340 23 打赏 收藏 转发到动态 举报
写回复
用AI写文章
23 条回复
切换为时间正序
请发表友善的回复…
发表回复
wumylove1234 2006-11-03
  • 打赏
  • 举报
回复
导分嫌疑!!
viena 2006-11-02
  • 打赏
  • 举报
回复
楼上都答了,帮顶接分!
mickeygg 2006-11-02
  • 打赏
  • 举报
回复
问题1:用javascript解决比较好
问题2:string[] values = TextBox1.Text.Split("\s");
woshibai112 2006-11-02
  • 打赏
  • 举报
回复
if(!cls.CheckExpression(txtCNRCD.Text.Trim(), "^[0-9]{1,"+ txtCNRCD.MaxLength +"}$"))
csShooter 2006-11-02
  • 打赏
  • 举报
回复
private bool nonNumberEntered = false;
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
nonNumberEntered = false;

// Determine whether the keystroke is a number from the top of the keyboard.
if (e.KeyCode < Keys.D0 || e.KeyCode > Keys.D9)
{
// Determine whether the keystroke is a number from the keypad.
if (e.KeyCode < Keys.NumPad0 || e.KeyCode > Keys.NumPad9)
{
// Determine whether the keystroke is a backspace.
if (e.KeyCode != Keys.Back)
{
// A non-numerical keystroke was pressed.
// Set the flag to true and evaluate in KeyPress event.
nonNumberEntered = true;
}
}
}

}


private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
// Check for the flag being set in the KeyDown event.
if (nonNumberEntered == true)
{
// Stop the character from being entered into the control since it is non-numerical.
e.Handled = true;
}

}
jcyluck 2006-11-02
  • 打赏
  • 举报
回复
问题1:调用keydown事件,当键入的数字 不是0-9时进行判断

问题2:这个问题没试过,但应该可以通过回判断回车符的位置来判断每一行,再得出每一行的值。楼主为什么不考虑使用combobox控件呢?
chen51630 2006-11-02
  • 打赏
  • 举报
回复
yeerh(边城浪) 问题1 的事件怎么会是在 Button 里执行的呢?能解释下吗?我看的不是很懂
chen51630 2006-11-02
  • 打赏
  • 举报
回复
恩,谢谢你们的支持,我试试看!
copico 2006-11-02
  • 打赏
  • 举报
回复
问题2:string[] str = this.textBox2.Lines;
lizhizhe2000 2006-11-02
  • 打赏
  • 举报
回复
楼上都答了,帮顶接分!
csShooter 2006-11-02
  • 打赏
  • 举报
回复
如何控制TextBox框在输入数据的时候只能输入数字,不能输入文本!!
---------------------------------------------------
方法1: 使用MaskedTextBox替换TextBox
方法2: 通过TextBox的KeyDown事件,判断e.KeyValue
.....

在TextBox 框的多行输入里,如何去分别读取每一行的数据给不同的变量!!
-------------------------------------------------
string strValue = this.textBox2.Lines[n]
oolongTea 2006-11-02
  • 打赏
  • 举报
回复
回复人:yeerh(边城浪) ( 四级(中级)) 信誉:100 2006-10-13 22:48:40 得分:8
?

private void Button_KeyPress(object sender, KeyPressEventArgs e)
{
int I = (int)e.KeyChar;
if (I == (int)Keys.Enter || I == (int)Keys.Back || I == (int)Keys.Left ||
I == (int)Keys.Right || I == (int)Keys.Left || I == (int)Keys.Delete)
{
return;
}

char[] charNum ={ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
if (Array.IndexOf(charNum, e.KeyChar) < 0)
{
e.Handled = true;
}
}
nearsnow 2006-11-02
  • 打赏
  • 举报
回复
D
EverBluesoft 2006-11-02
  • 打赏
  • 举报
回复
在KEYPRESS中添加if(e.keyChar<'0' || e.keyChar>'9')
{
e.handled=true;
}
chenyongjin 2006-11-02
  • 打赏
  • 举报
回复
if(!cls.CheckExpression(txtCNRCD.Text.Trim(), "^[0-9]{1,"+ txtCNRCD.MaxLength +"}$"))


string[] values = TextBox1.Text.Split("\s");
早起晚睡 2006-11-02
  • 打赏
  • 举报
回复
来晚了
jacobwc 2006-11-02
  • 打赏
  • 举报
回复
答案都有了
mark
e251396 2006-11-02
  • 打赏
  • 举报
回复
使用正则表达式呀,
rongkun06 2006-11-02
  • 打赏
  • 举报
回复
路过,学习!
dlzhangln 2006-11-02
  • 打赏
  • 举报
回复
接分
加载更多回复(3)

110,825

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧