开发者

To disable spaces entering textbox

开发者 https://www.devze.com 2023-01-30 12:34 出处:网络
In MFC开发者_C百科 How to disable spaces entering textboxJust supply the own OnKeyDown event handler and filter out the space keys:

In MFC开发者_C百科 How to disable spaces entering textbox


Just supply the own OnKeyDown event handler and filter out the space keys:

 void MyEditControl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
 {
   if (nChar == 32)
   {
     // kill the space key down event
     return;
   }

   // let edit control handle the other keys
   CEdit::OnKeyDown(nChar, nRepCnt, nFlags);
 } 


you can update the user entry on OnChangeControl as follows:

if ((m_strYOURCONTROL[m_strYOURCONTROL.GetLength() - 1]) == ' ')
{
    m_strYOURCONTROL = m_strYOURCONTROL.Mid(0, m_strYOURCONTROL.GetLength() - 1);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号