当前位置:   article > 正文

[VC++]限制CEdit(Edit Contrl)只能输入数字和小数点_mfc中,怎么设置edit只能输入数字和小数点

mfc中,怎么设置edit只能输入数字和小数点
  1. void CSettingcategory::OnEnChangeEdit2()
  2. {
  3. CString csAreaS;
  4. GetDlgItem( IDC_EDIT2 )->GetWindowText( csAreaS );
  5. // 只允许输数据
  6. int nStringLength = csAreaS.GetLength();
  7. int nDotCount = 0;
  8. // 点字符不能多于1个
  9. for ( int nIndex = 0; nIndex < nStringLength; nIndex++ )
  10. {
  11. if ( csAreaS[ nIndex ] == '.' )
  12. {
  13. nDotCount++;
  14. if ( nDotCount > 1 )
  15. {
  16. CString csTmp;
  17. csTmp = csAreaS.Left( nIndex );
  18. csTmp += csAreaS.Right( csAreaS.GetLength() - nIndex - 1 );
  19. //csRadius = csRadius.Left( nIndex + 1 ) + csRadius.Right( nStringLength - ( nIndex + 1 ) - 1 );
  20. GetDlgItem( IDC_EDIT2 )->SetWindowText( csTmp );
  21. return;
  22. }
  23. }
  24. }
  25. // 不允许输入数字和点以外的字符
  26. for ( int nIndex = 0; nIndex < nStringLength; nIndex++ )
  27. {
  28. if ( csAreaS[ nIndex ] != '.' && ( csAreaS[ nIndex ] > '9' || csAreaS[ nIndex ] < '0' ) )
  29. {
  30. csAreaS = csAreaS.Left( nIndex ) + csAreaS.Right( csAreaS.GetLength() - nIndex - 1 );
  31. GetDlgItem( IDC_EDIT2 )->SetWindowText( csAreaS );
  32. return;
  33. }
  34. }
  35. }


声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/83046
推荐阅读
相关标签
  

闽ICP备14008679号