- 1、本文档共10页,可阅读全部内容。
- 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
文本控制程序
?private System.Windows.Forms.TextBox textBox1; ??private string text; ??public Form1() ??{ ?? text = textBox1.Text; ??} ??private void textBox1_TextChanged(object sender, System.EventArgs e) ??{ ?? int len = text.Length; ??if(len textBox1.Text.Length) ??{ ?? int index = textBox1.Text.IndexOf(text); ?? char c = (textBox1.Text.Remove(index,text.Length))[0]; ?? if(c.CompareTo(0) 0||c.CompareTo(9) 0) ?? { ?? textBox1.Text = text; ?? textBox1.SelectionStart = text.Length; ?? } ?? } ?? text = textBox1.Text; ?? ??} private void m_textBox_KeyDown(object sender, KeyEventArgs e) {
// Initialize the flag to false.
m_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.
m_nonNumberEntered = true;
}
if(this.textBox1.TextLength0) { ?this.textBox1.Text=? ?this.textBox1.Text.Substring(0,this.textBox1.Text.Length-1);? }
if(e.KeyChar!=8!Char.IsDigit(e.KeyChar))???{?????e.Handled = true;???}??}
Private Sub Text1_KeyPress (KeyAscii As Integer)
If KeyAscii = 13 Then
SendKeys “{tab}”
KeyAscii = 0
End If
End Sub
百度空间?|?百度首页? | 登录
云舞正行
......至夫子继圣,独秀前哲,熔钧六经,必金声而玉振;雕琢性情,组织辞令,木铎而千里应,席珍流而万世响,写天地之辉光,晓生民之耳目矣.?
主页博客相册|个人档案 |好友
? 查看文章 ? 判断文本框的信息是不是数值的控制[转]
2007-08-02 11:48
凡用过VB的读者都知道,VB中有一个文本框(TextBox控件),它可显示设计时程序员输入的或运行时用户输入的或在代码中赋予的信息(包括字母、数字和其他符号)。但在很多场合我们需要的仅仅是数值数据,这时在TextBox中无意输入的非数值数据就会给我们带来不便,因此需将非数值信息过滤掉。为实现这一目标,我们设计一个只能输入数值的“数值框”。
初步设想与比较
设计时,我们通常采用IsNumeric函数来判断文本框的信息是
文档评论(0)