现在的位置: 首页 > 综合 > 正文

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

2013年08月31日 ⁄ 综合 ⁄ 共 1037字 ⁄ 字号 评论关闭

 自动换行设置的时候,要在EDIT控件的属性中选中"multiline"的属性和Auto_HScroll、Vertical scroll
     经过多次测试,总结出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.

抱歉!评论已关闭.