CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 1999
    Posts
    57

    How can I Put a new line in an edit control dynamically



    Hi,

    How can I put a new line in an edit control dynamically....

    regards,

    Lijo

  2. #2
    Join Date
    Apr 1999
    Posts
    191

    Brute force



    You have to get the text from the edit control with CWnd::GetWindowText(). Then change the text according to your needs, and send it back to the edit control with CWnd::SetWindowText().

  3. #3
    Join Date
    May 1999
    Posts
    26

    Re: Brute force

    A way to do it without having to take all the text and replace it is to take the cursor to the last position of the edit box, and then use ReplaceSel() to replace the current selected text (the selection will be empty so it will be actually an insertion).

    To take the cursor to the last position I do this:

    m_Edit.SetSel(0,-1,FALSE);
    m_Edit.SetSel(-1,0,TRUE);



    The first SetSel will select all the text in the edit box, the FALSE indicates that the cursor will be taken (scrolled) to the selection.
    The second call will select no text, but it will not move the cursor.

    Once the cursor is at the end you can add text :

    m_Edit.ReplaceSel("new line of text")




    Besides, another thing is that you can't put a new line using:

    myEdit.SetWindowText("\n").



    You have to do it like this:

    myEdit.SetWindowText((CString)'\r'+(CString)'\n').



    Isn't that annoying?.

    It is incredible that MFC doesn't provide such simple features for such a wide-use control.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured