当numericUpDown内容用BackSpace键去除变为空白时,引发CausesValidation,让程序停顿数秒无反应, 若将CausesValidation设为False,暂时是不会发生校验而停顿。但numericUpDown内容空白仍会引发些许问题,于是我设定了一个interval =1000的timer1内容为:
private void timer1_Tick_1(object sender, System.EventArgs e)
{
if(numericUpDown1.Value.Equals(null))
{numericUpDown1.Value = 0;}
}此写法又会引发验证,若不输入任何数值于numericUpDown1时,则冻结数秒,numericUpDown1.Value才变成0。有没有办法使numericUpDown控件输入值为空白时,自动改为0,且不产生任何冻结或停顿呢?

解决方案 »

  1.   

    不知道这段代码是不是你要的
    numericUpDown1.CausesValidation = false;

    private void numericUpDown1_Leave(object sender, System.EventArgs e)
    {
    if(numericUpDown1.Value.Equals(null))
    numericUpDown1.Value=0;
    }
      

  2.   

    如此若numericUpDown1为空白时
    点选其它控制项
    让numericUpDown1失去焦点
    仍会让程序冻结7秒左右
    接着numericUpDown1.Value会变回初始值(若一开始设为1, 即变回1)
      

  3.   

    private void numericUpDown1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
    {
    if(8==(int)e.KeyChar)
    e.Handled =true;
    }这段代码是不让用户按退格键.这回可以了吧.
      

  4.   

    只得这样了
    请问del跟鼠标右键的参数是什么
    该到哪里查找呢
      

  5.   

    原来e.KeyChar==(char)Keys.就会显示出来啦,谢啦