MFC edit Box Album

Source: Internet
Author: User

In the Wrap settings, select the properties of "Multiline" and Auto_hscroll, Vertical Scroll in the properties of the edit control.

After many tests, summed up the VC editing box (edit) automatic line-wrapping and automatic scrolling method.

method One: (when edit is mapped to a CString)
m_string = m_string + snewstring + "\ r \ n"

Wrap line (where m_string is the CString object associated with the edit basket)
UpdateData (FALSE);

This method can only be wrapped automatically, not automatically scrolling to the last line.

method Two: (when edit is mapped to an edit)
M_edit.setsel (-1,-1); Automatic scrolling (where M_edit is the edit control object associated with the edit basket)
M_edit.replacesel (snewstring+ "\ r \ n"); Wrap Line

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

Above, M_string, M_edit. The member variable to add to the edit box, respectively, snewstring the string to display

method Three: empty all contents to 200 rows

1 intilinenum=M_editlog.getlinecount ();2      if(ilinenum<= $)3      {4M_editlog.setsel (-1, -1);5M_editlog.replacesel (str+"\r\n\r\n");6      }   7      Else8      {9M_editlog.setsel (0, -1);Ten m_editlog.clear (); One      A}

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

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

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

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

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

"MFC" about the editbox of scroll bars in general, if the content in EditBox is static, you can easily slide the scrollbar based on the property. (You can set its properties for dialog)
However, if the content in EditBox is dynamically refreshed, the scroll bar (either horizontal or vertical) is repositioned at the beginning of each refresh.
Therefore, if you want to keep the scrollbar position intact each time you refresh it, you need to do some processing. -------------------------------------------------------------------------
For example:
1 //Timer so that it refreshes the contents of the editbox at a certain time. 2 voidXxx::ontimer (uint_ptr nidevent)3 {4         //set the content to be output5 CString str;6M_str + ="Line = =";7m_nlinecount++;8Str. Format ("M", m_nlinecount);9M_str + = str +"==";TenM_str + ="01234567890123456789012345678901234567890123456789\r\n"; One  A        //gets the position of the horizontal scroll bar and the vertical scroll bar before the flush -M_position.x =m_edit1. GetScrollPos (Sb_horz);  -M_POSITION.Y =m_edit1. GetScrollPos (Sb_vert); the  -        //get the scroll range of the horizontal scroll bar -M_edit. Getscrollrange (Sb_horz, &m_nminhscroll, &m_nmaxhscroll); -m_flag++; +        if(M_flag = =1 ) -        { +                 //gets the number of characters in the first row AMaxLen =m_str. GetLength (); at        } -  -         //Refresh the content in EditBox - M_edit. Setwindowtexta (M_STR); -       //sets the position of the horizontal and vertical scroll bars (position before the refresh) -       if(M_nmaxhscroll! =m_nminhscroll) in      { -                 //This conversion directly affects whether you can position the horizontal scroll bar before it refreshes to                 intNChar = (MaxLen * m_position.x)/(M_nmaxhscroll-m_nminhscroll); + m_edit1. Linescroll (M_POSITION.Y, NChar); -       } the       Else *      { $ m_edit1. Linescroll (M_POSITION.Y);Panax Notoginseng      } - Cdialog::ontimer (nidevent); the}

----Http://huagx770.spaces.live.com/blog/cns!C2B50FE280E36778!266.entry

Briefly, since the Ceditbox::linescroll () function is capable of setting scrolling content, the 2nd

A parameter (usually the default) requires the number of characters to be passed in, i.e. the number of characters to be scrolled horizontally, so the conversion: NChar = (MaxLen * m_position.x)/(M_nmaxhscroll-m_nminhscroll);
Can.-----------------------------------------------------

MFC edit Box Album

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.