[转][VC++]限制CEdit(Edit Contrl)只能输入数字和小数点
2015-11-03 00:11
381 查看
void CSettingcategory::OnEnChangeEdit2()
{
CString csAreaS;
GetDlgItem( IDC_EDIT2 )->GetWindowText( csAreaS );
// 只允许输数据
int nStringLength = csAreaS.GetLength();
int nDotCount = 0;
// 点字符不能多于1个
for ( int nIndex = 0; nIndex < nStringLength; nIndex++ )
{
if ( csAreaS[ nIndex ] == '.' )
{
nDotCount++;
if ( nDotCount > 1 )
{
CString csTmp;
csTmp = csAreaS.Left( nIndex );
csTmp += csAreaS.Right( csAreaS.GetLength() - nIndex - 1 );
//csRadius = csRadius.Left( nIndex + 1 ) + csRadius.Right( nStringLength - ( nIndex + 1 ) - 1 );
GetDlgItem( IDC_EDIT2 )->SetWindowText( csTmp );
return;
}
}
}
// 不允许输入数字和点以外的字符
for ( int nIndex = 0; nIndex < nStringLength; nIndex++ )
{
if ( csAreaS[ nIndex ] != '.' && ( csAreaS[ nIndex ] > '9' || csAreaS[ nIndex ] < '0' ) )
{
csAreaS = csAreaS.Left( nIndex ) + csAreaS.Right( csAreaS.GetLength() - nIndex - 1 );
GetDlgItem( IDC_EDIT2 )->SetWindowText( csAreaS );
return;
}
}
}
{
CString csAreaS;
GetDlgItem( IDC_EDIT2 )->GetWindowText( csAreaS );
// 只允许输数据
int nStringLength = csAreaS.GetLength();
int nDotCount = 0;
// 点字符不能多于1个
for ( int nIndex = 0; nIndex < nStringLength; nIndex++ )
{
if ( csAreaS[ nIndex ] == '.' )
{
nDotCount++;
if ( nDotCount > 1 )
{
CString csTmp;
csTmp = csAreaS.Left( nIndex );
csTmp += csAreaS.Right( csAreaS.GetLength() - nIndex - 1 );
//csRadius = csRadius.Left( nIndex + 1 ) + csRadius.Right( nStringLength - ( nIndex + 1 ) - 1 );
GetDlgItem( IDC_EDIT2 )->SetWindowText( csTmp );
return;
}
}
}
// 不允许输入数字和点以外的字符
for ( int nIndex = 0; nIndex < nStringLength; nIndex++ )
{
if ( csAreaS[ nIndex ] != '.' && ( csAreaS[ nIndex ] > '9' || csAreaS[ nIndex ] < '0' ) )
{
csAreaS = csAreaS.Left( nIndex ) + csAreaS.Right( csAreaS.GetLength() - nIndex - 1 );
GetDlgItem( IDC_EDIT2 )->SetWindowText( csAreaS );
return;
}
}
}
相关文章推荐
- C++基础---类(class)
- leetcode笔记:House Robber
- c++调用ado链接mssql数据库详解
- leetcode笔记:Maximum Subarray(最大子串和问题)
- 熟悉预处理标识符: __LINE__ __FILE__ __DATE__ # ##
- 宏和函数的区别
- 【LeetCode从零单刷】Search in Rotated Sorted Array I & II
- 用C++/CLI搭建C++和C#之间的桥梁(一)—— 简介
- c++11特性之std::thread--初识二
- c++11特性之std::thread--初识二
- C语言预处理 # 和## 运算符
- 对C++中文件输出流成员函数的认识
- 任意进制整数之间的相互转换(C++实现)
- C++练习
- C++重载运算符函数需知
- c++ primer第五版(中文)习题答案 第二章第五节-处理类型
- 导弹拦截<DP><贪心><C++>
- c++11特性之std::thread--初识
- c++11特性之std::thread--初识
- c++栈和队列