經過多次測試,總結出VC編輯框(EDIT)的自動換行與自動滾屏的方法。
方法一: (當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();
if(iLineNum<=200)
{
m_EditLog.SetSel(-1, -1);
m_EditLog.ReplaceSel(str+"\r\n\r\n");
}
else
{
m_EditLog.SetReadOnly(FALSE); //此處處理edit的只讀設爲可讀可
m_EditLog.SetSel(0, -1);
m_EditLog.Clear();
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.