textbox只能输入数字

txtLocPort.KeyPress += Pub.KeyPress_NumInput;

 /// <summary>
        ///  数字输入 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public static void KeyPress_NumInput(object sender, KeyPressEventArgs e)
        {
            if ((e.KeyChar < '0' || e.KeyChar > '9') && e.KeyChar != 8)
                e.KeyChar = (char)0;
        }

 

posted @ 2013-06-20 17:08  nygfcn  阅读(194)  评论(0编辑  收藏  举报