输入文本框

问题描述:

在MFC中如何禁用空格输入文本框要禁用空间输入文本框

+0

[MFC控件在vC++中禁用mfc文本框中的输入空格](http://stackoverflow.com/questions/442635 1/mfc-control-disable-entering-spaces-in-mfc-textbox-in-vc) – Adnan 2010-12-13 13:05:19

您可以按如下更新OnChangeControl用户条目:

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

如何将光标置于mfc.cursor中的文本末尾指向输入空格时的第一个字符。 – sun 2010-12-13 14:06:55

+0

在这个实现中,你只需检查最后输入的字符。 – Sunscreen 2010-12-14 06:57:00

+0

当我按下空格时,我正在输入光标的任何字符都将移动到开始位置。 – sun 2010-12-14 13:53:05

只需提供自己的的onkeydown事件处理程序,并筛选出空格键:

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); 
}