c# 限制textbox的输入范围和长度(长度不用maxlength方法)

在写这篇文章之前,xxx已经写过了几篇关于改主题的文章,想要了解的朋友可以去翻一下之前的文章

    每日一道理
“上下五千年,龙的看火不灭;古有愚公志,而今从头越…… ”站在新世纪的门槛上,我们的追求就是让祖国灿烂的喜悦飞扬在美好的明天……
using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;



namespace WindowsFormsApplication1

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

        static int i = 0;

        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)

        {



            if (e.KeyChar < '0' || e.KeyChar > '9')

            {

                e.Handled = true;

            }

            else {

                i++;

                if (i > 8)

                {

                    e.Handled = true;//不处置

                }

            }

        }

    }

}

    
 

文章结束给大家分享下程序员的一些笑话语录: 小沈阳版程序员~~~ \n程序员其实可痛苦的了......需求一做一改,一个月就过去了;嚎~ \n需求再一改一调,一季度就过去了;嚎~ \n程序员最痛苦的事儿是啥,知道不?就是,程序没做完,需求又改了; \n程序员最最痛苦的事儿是啥,知道不? 就是,系统好不容易做完了,方案全改了; \n程序员最最最痛苦的事儿是啥,知道不? 就是,系统做完了,狗日的客户跑了; \n程序员最最最最最痛苦的事儿是啥,知道不? 就是,狗日的客户又回来了,程序给删没了!

你可能感兴趣的:(length)