如何才能只让edittext中的行数固定住,比如只能有5行,无论是用户手动回车,还是edittext的自动回车,都不会超过5行字   请告知高手帮忙。

解决方案 »

  1.   

    SetLimitText(UINT nMax);
    可以固定行数的   
      

  2.   

    CString m_edit; //与IDC_EDIT1关联
    CString m_strText; //并初始化为空
    响应IDC_EDIT1的EN_UPDATE消息
    void CTestEditDlg::OnUpdateEdit1() 
    {
    CEdit *pEdit = (CEdit*)GetDlgItem(IDC_EDIT1);
    if (pEdit->GetLineCount() <= 5)
    {
    pEdit->GetWindowText(m_strText);
    }
    m_edit = m_strText;
    UpdateData(FALSE);

    }
      

  3.   

    CEdit::GetLineCount 
    int GetLineCount( ) const;Return ValueAn integer containing the number of lines in the multiple-line edit control. If no text has been entered into the edit control, the return value is 1.ResCall this function to retrieve the number of lines in a multiple-line edit control. GetLineCount is only processed by multiple-line edit controls.
      

  4.   

    重载edit,
    然后响应OnCharvoid CMyEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) 
    {
    // TODO: Add your message handler code here and/or call default
    if(nChar == VK_RETURN)
    {
    if(GetLineCount() >=5)
    return;
    } CEdit::OnChar(nChar, nRepCnt, nFlags);
    }
      

  5.   

    还要预防拷贝,响应EN_UPDATE消息
    void CMyEdit::OnUpdate() 
    {
    if(GetLineCount() >=5) Undo();
    }