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

來源:互聯網
上載者:User

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.