首页 > 其他 > 详细

16 如何使一个文本框只能接受数字

时间:2014-06-24 21:46:03      阅读:324      评论:0      收藏:0      [点我收藏+]
(1) 使用NumericUpDown
(2) 处理KeyPress 按钮

(3) 处理Text_Changed 事件


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Text.RegularExpressions;



namespace MVA20QuestionWin
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

       private void txtNumeric_TextChanged(object sender, EventArgs e)
        {
        //    if (!Regex.IsMatch("[0-9]", txtNumeric.Text))
        //    {
        //        MessageBox.Show("Please enter only numbers.");
        //        txtNumeric.Text.Remove(txtNumeric.Text.Length - 1);
        //    }
        }

        private void txtNumeric_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = !char.IsDigit(e.KeyChar); //&& !char.IsControl(e.KeyChar);
        }

    }
}


16 如何使一个文本框只能接受数字,布布扣,bubuko.com

16 如何使一个文本框只能接受数字

原文:http://blog.csdn.net/u011685627/article/details/33471549

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!