只能输入+ 0 1 2 3 4 5 6 7 8 9这几个字符,按其他键不响应

解决方案 »

  1.   

    我知道的一种方法是重载CEdit,创建一个自己个类,如:CNumEdit。
    在CNumEdit中处理按键按下的情况,滤掉其他的字符,只保留你要的字符。
      

  2.   

    如果是SDK的话,可以用子类化,你用这个词找一下会找到一大堆代码,如果是用MFC的话可以从CEdit这个类派生子类,在子类中进行过滤
      

  3.   

    我已经用DDX_TEXT和一个TCHAR数组关联上了,最终我是要取TCHAR这个数组的值的
      

  4.   

    属性--Styles--Number勾上(左下角)
      

  5.   

    响应CEdit的EN_CHANGE消息
    void XXX::OnChangeEdit1() 
    {
    // TODO: If this is a RICHEDIT control, the control will not
    // send this notification unless you override the CDialog::OnInitDialog()
    // function and call CRichEditCtrl().SetEventMask()
    // with the ENM_CHANGE flag ORed into the mask.

    // TODO: Add your control notification handler code here
        UpdateData(true);
    int length=m_str.GetLength()-1; //m_str控件的CString型变量,m_ctr控制型变量
    if(length>=0){
    int tem=m_str.GetAt(length);
    if(tem>57||tem<48){//除了0~9
    m_str=m_str.Left(length);
    UpdateData(false);
    m_ctr.SetSel(m_ctr.GetWindowTextLength(),m_ctr.GetWindowTextLength());

    }
    }
    }
      

  6.   

    重载OnChar(),在里边随便进行控制
      

  7.   

    可以设置style的,设成Number就可以了
      

  8.   

    也可以自定义EN_CHANGE消息来控件字符的输入。。