VC編輯框(EDIT)的自動換行、自動滾屏 、自動清空

 自動換行設置的時候,要在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.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章