The use of MFC EDIT - automatic scrolling

When setting automatic line wrapping, select the "multiline" property and Auto_HScroll, Vertical scroll in the properties of the EDIT control.

After many tests, the method of automatic line wrapping and automatic scrolling of the VC edit box (EDIT) is concluded.

Method 1: (When EDIT is mapped to a CString)
m_String = m_String + sNewString + "\r\n"   

//Auto wrap (where m_String is the CString object associated with the EDIT basket)
UpdateData(false);

This method can only do automatic line wrapping, and will not automatically scroll to the last line.

Method 2: (When EDIT is mapped to an EDIT)
m_Edit.SetSel(-1, -1); //Auto scroll (where m_Edit is the EDIT control object associated with the EDIT basket)
m_Edit.ReplaceSel(sNewString+"\r\n "); //Auto wrap

This method can automatically wrap, and automatically scroll to the last line.

Above, m_String and m_Edit. are the member variables added to the edit box respectively; sNewString is the string to be displayed

If not, add UpdateWindow(); try

Method 3: Empty all content when it reaches 200 lines

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();
    
     }

If you need to clear it directly, use it directly

    m_EditLog.SetWindowText("");


Taken from 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.

http://www.pcming.com/studio/showart.asp?id=443

----------------------------------

------------------------------------------------------

How to automatically clear EditBox in VC? ? ? http://topic.csdn.net/u/20080311/16/70b6c4af-0a1f-418c-b4d0-bb336ababb9b.html

--------------------------------------------------------

[MFC] About the positioning of the scroll bar in EditBox

In general, if the content in the EditBox is static, the scrollbar can be easily swiped based on the properties.
   (For Dialog, its properties can be set)
   However, if the content in the EditBox is dynamically refreshed, then after each refresh, the scroll bar (whether the water
flat, or vertical) will be repositioned at the beginning.
    Therefore, if you want to keep the scroll bar position unchanged every time you refresh, you need to do some processing.
-------------------------------------------------- -----------------------
For example:
//Timer, let it refresh the contents of the EditBox at regular intervals.
void XXX::OnTimer(UINT_PTR nIDEvent)
{
        //Set the content to be output
       CString str;
       m_str +="Line ==";
       m_nLineCount++;
       str.Format( "%4d", m_nLineCount );
       m_str += str + " ==";
       m_str +="01234567890123456789012345678901234567890123456789\r\n";

       //Get the position of the horizontal scroll bar and the vertical scroll bar before refresh
        m_position.x = m_edit1.GetScrollPos( SB_HORZ );
       m_position.y = m_edit1.GetScrollPos( SB_VERT );

       //Get the scrolling range of the horizontal scroll bar
       m_edit.GetScrollRange( SB_HORZ, &m_nMinHScroll , &m_nMaxHScroll );
       m_flag++;
       if( m_flag == 1 )
       {
                //Get the number of characters in the first line
                maxLen = m_str.GetLength();
       }

        //Refresh the content in EditBox
       m_edit.SetWindowTextA( m_str );
      //Set the position of the horizontal and vertical scroll bars (the position before refresh)
      if( m_nMaxHScroll != m_nMinHScroll )
     {
                //This conversion directly affects whether the horizontal scroll bar can be positioned before the refresh
                int nChar = ( maxLen * m_position.x ) / (m_nMaxHScroll - m_nMinHScroll);
                m_edit1.LineScroll( m_position.y, nChar );
      }
      else
     {
                m_edit1 .LineScroll( m_position.y );
     }
     CDialog::OnTimer(nIDEvent);
}

------------------------------------------------http: //huagx770.spaces.live.com/blog/cns!C2B50FE280E36778!266.entry
    Briefly explain, because the CEditBox::LineScroll() function can set the scrolling content, but because of its second

This parameter (usually the default) requires the number of characters to be passed in, that is: the number of characters to be scrolled horizontally, so
Do the conversion:
    nChar = ( maxLen * m_position.x ) / (m_nMaxHScroll - m_nMinHScroll);
即可。

-----------------------------------------------------

MFC makes double-buffered flicker-free subtitle scrollbar

From: http://hi.baidu.com/jam12315/blog/item/63f4fe0902fb438ad1581bbf.html
For your safety, please only open URLs from reliable sources

open website     cancel

From: http://hi.baidu.com/bjwyl66/blog/item/47719f3abcb196cfd4622534.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325870302&siteId=291194637
Recommended