在自动换行设置的时候,要在EDIT控件的属性中选中"multiline"的属性和Auto_HScroll、Vertical scroll。
方法一: (当EDIT映射到一CString时)
m_String = m_String + sNewString + "\r\n"
//自动换行(其中m_String是EDIT筐所关联的CString对象)
UpdateData(false);
此法只能做到自动换行,不会自动滚屏到最后一行。
方法二: (当EDIT映射到一EDIT时)
m_Edit.SetSel(-1, -1);
//自动滚屏(其中m_Edit是EDIT筐所关联的EDIT控制对象)
m_Edit.ReplaceSel(sNewString+"\r\n");
//自动换行
此法可以做到自动换行,并自动滚屏到最后一行。
以上,m_String、m_Edit.分别为给编辑框添加的成员变量;sNewString 为要显示的字符串
方法三: 到200行时将所有内容清空
int iLineNum=m_EditLog.GetLineCount();
m_EditLog.SetReadOnly(FALSE); //此处处理edit的只读设为可读可
m_EditLog.SetReadOnly();//恢复只读
取自msdn
void SetSel( int nStartChar, int nEndChar, BOOL bNoScroll = FALSE );
Parameters
nStartChar
Specifies the starting position. If nStartChar is 0 and nEndChar is –1, all the text in the edit control is selected. If nStartChar is –1, any current selection is removed.
nEndChar
Specifies the ending position.