金沙贵宾会官网|金沙贵宾会登录-官网

【A】金沙贵宾会官网超高的返奖率为娱乐者提供资金保障,所以金沙贵宾会登录官网更加的方便了你的娱乐,申请88元彩金,因为在当中不仅仅只有游戏。

TextBox中只能输入数字的几种常用方法

日期:2019-09-26编辑作者:网络软件

private void txtGoodsGroup_KeyPress(object sender, KeyPressEventArgs e)
{
base.OnKeyPress;
if e.KeyChar >= 65296 && e.KeyChar <= 65305)
{
e.KeyChar = e.KeyChar - 65248);
}
}

TextBox中只能输入数字的几种常用方法(C#)

Form and Control KeyEvent

一、Form的KeyEvent

图片 1

KeyCode:

  1. private void Form1_KeyDown(object sender, KeyEventArgs e)
  2. {
  3. if ((e.Modifiers == Keys.Control) && (e.KeyCode == Keys.Z))
  4. {
  5. this.cancelHandler();
  6. }
  7. else if ((e.Modifiers == Keys.Control) && (e.KeyCode == Keys.S))
  8. {
  9. this.saveHandler();
  10. }
  11. else
  12. e.Handled = true;
  13. }

二、Control’s KeyEvent

检测输入control的字符的正确性。

  1. private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
  2. {
  3. if (e.KeyChar == 'b')
  4. mPwFlag[0] = e.KeyChar;
  5. if (e.KeyChar == 'a')
  6. mPwFlag[1] = e.KeyChar;
  7. if (e.KeyChar == 't')
  8. mPwFlag[2] = e.KeyChar;
  9. if (e.KeyChar == '1')
  10. mPwFlag[0] = e.KeyChar;
  11. if (e.KeyChar == '2')
  12. mPwFlag[1] = e.KeyChar;
  13. if (e.KeyChar == '3')
  14. mPwFlag[2] = e.KeyChar;
  15. if (mPwFlag[0] == 'b' && mPwFlag[1] == 'a' && mPwFlag[2] == 't')
  16. {
  17. mPwFlag[0] = '0';
  18. mPwFlag[1] = '0';
  19. mPwFlag[2] = '0';
  20. BatCreateTopic bct = new BatCreateTopic(this);
  21. this.button3.Visible = true;
  22. bct.ShowDialog(this);
  23. }
  24. }

and Control KeyEvent 一、Form的KeyEvent KeyCode: private void Form1_KeyDown(object sender, KeyEventArgs e) { if ((e.Modifiers == Keys.Control) (e.KeyCode == Keys.Z)) { this...

回车

private void tBox_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 0x20) e.KeyChar = (char)0;  //禁止空格键
            if ((e.KeyChar == 0x2D) && (((TextBox)sender).Text.Length == 0)) return;   //处理负数
            if (e.KeyChar > 0x20)
            {
                try
                {
                    double.Parse(((TextBox)sender).Text + e.KeyChar.ToString());
                }
                catch
                {
                    e.KeyChar = (char)0;   //处理非法字符
                }
            }
        }

e.KeyChar == 13

private void TextBox_KeyPress(object sender, KeyPressEventArgs e)
   {
    if(e.KeyChar!=8&&!Char.IsDigit(e.KeyChar))
    {
      e.Handled = true;
    }
   }
或者private void TextBox_KeyPress(object sender, KeyPressEventArgs e)
   {
    if(e.KeyChar!='b'&&!Char.IsDigit(e.KeyChar))
    {
      e.Handled = true;
    }

}

private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if(e.KeyChar!='b')//这是允许输入退格键
{
if((e.KeyChar<'0')||(e.KeyChar>'9'))//这是允许输入0-9数字
{
e.Handled = true;
}
}
}

private void button1_Click(object sender, EventArgs e)
{
string text = this.textBox1.Text;
if (text != null)
MessageBox.Show(text);
}

private void textBox1_Validating(object sender, CancelEventArgs e)
{
const string pattern = @"^d+.?d+$";
string content = ((TextBox)sender).Text;

if (!(Regex.IsMatch(content, pattern)))
{
errorProvider1.SetError((Control)sender, "只能输入数字!");
e.Cancel = true;
}
else
errorProvider1.SetError((Control)sender, null);
}

private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if(e.KeyChar=='.' && this.textBox1.Text.IndexOf(".")!=-1)
{
e.Handled=true;
}

if(!((e.KeyChar>=48 && e.KeyChar<=57) || e.KeyChar=='.' || e.KeyChar==8))
{
e.Handled=true;
}

}

  private void tbx_LsRegCapital_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!Char.IsNumber(e.KeyChar) && !Char.IsPunctuation(e.KeyChar) && !Char.IsControl(e.KeyChar))
            {
                e.Handled = true;//消除不合适字符
            }
            else if (Char.IsPunctuation(e.KeyChar))
            {
                if (e.KeyChar != '.' || this.textBox1.Text.Length == 0)//小数点
                {
                    e.Handled = true;
                }
                if (textBox1.Text.LastIndexOf('.') != -1)
                {
                    e.Handled = true;
                }
            }      
        }

利用ASCII码处理办法、
{

            if ((e.KeyChar <= 48 || e.KeyChar >=57) && (e.KeyChar != 8) && (e.KeyChar != 46))
              e.Handled = true;
================48代表0,57代表9,8代表空格,46代表小数点
}

来自:

本文由金沙贵宾会官网发布于网络软件,转载请注明出处:TextBox中只能输入数字的几种常用方法

关键词:

The Coroutine

关于Coroutine 金沙贵宾会官网,说到coroutine就不的不说subroutine,也就是我们常用到的一般函数。调用一个函数开始执行...

详细>>

2008配置使用动态IP和备用地址,配置内网DNS实现

用DNS地址限制网站访问 在设置DNS地址之前我们需要知道DNS地址是什么? DNS地址是一个域名服务器地址,它可以把用户...

详细>>

C语言编码规范,每一个程序员要遵守的一些优秀

无论你是业余的还是专业的程序员,正确的编程风格,不但有助于提升软件产品的功能,还可以明显减少软件灾难的...

详细>>

牛客练习赛10

Minimal string CodeForces - 797C Minimal string CodeForces,minimalcodeforces Minimal string CodeForces - 797C 题意:有一个字符串s和空串t和...

详细>>