绑定textbox的KeyPress事件,代码如下


        /// <summary>
        /// 监听同时下载数量焦点键盘按键,仅允许退格键与0~9键
        /// </summary>
        /// <param name=”sender”></param>
        /// <param name=”e”></param>
        private void tb_len_KeyPress(object sender, KeyPressEventArgs e)
{
if ((int)e.KeyChar != 8)
{
if ((int)e.KeyChar >= ‘0’ && (int)e.KeyChar <= ‘9’)
{
if (tb_len.Text == “” && (int)e.KeyChar == ‘0’)
{
e.Handled = true;
}
else
{
e.Handled = false;
}
}
else
{
e.Handled = true;
}
}
}

 

 

说点什么
支持Markdown语法
好耶,沙发还空着ヾ(≧▽≦*)o
Loading...