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.
可以固定行数的
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);
}
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.
然后响应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);
}
void CMyEdit::OnUpdate()
{
if(GetLineCount() >=5) Undo();
}