方法一:(当EDIT映射到一CString时) m_String = m_String + sNewString + "\r\n" //自动换行
UpdateData(false);
此法只能做到自动换行,不会自动滚屏到最后一行。
方法二:(当EDIT映射到一EDIT时)m_Edit.SetSel(-1, -1); //自动滚屏
m_Edit.ReplaceSel(sNewString+"\r\n"); //自动换行
UpdateData(true);
此法可以做到自动换行,并自动滚屏到最后一行。
以上,m_String、m_Edit.分别为给编辑框添加的成员变量;sNewString 为要显示的字符串
注意二法中UpdataData参数的区别。
修改编辑框的属性:Auto_HScroll等用处不大。
在编辑框的“样式”单中将属性设为 WantReturn MutiLine VerticalScroll,去掉Auto HScroll。
如果是在输出到编辑框中需要换行,可以用\r\n。
方法三:( 到200行时将所有内容清空 )
int iLineNum=m_EditLog.GetLineCount();
if(iLineNum<=200)
{
m_EditLog.SetSel(-1, -1);
m_EditLog.ReplaceSel(str+"\r\n\r\n");
}
else
{
m_EditLog.SetSel(0, -1);
m_EditLog.Clear();
}
取自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.