VC编辑框(EDIT)的自动换行、自动滚屏 、到指定行数自动清空

在自动换行设置的时候,要在EDIT控件的属性中选中"multiline"的属性和Auto_HScroll、Vertical scroll。.

http://blog.sina.com.cn/s/blog_41604f160100877c.html

经过多次测试,总结出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.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.

原文地址:https://www.cnblogs.com/mfryf/p/2349732.html