CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Sep 2003
    Posts
    90

    Multiline Edit control

    In Multiline Edit control ..when i set the text which contains
    '\n' character using the SetWindowText function ,it's not
    moved onto the next line ,but instead it displays a thick line for
    the '\n' and all the characters are displayed in the same line.

    How can i display the text onto the next line ..if the string
    contains a '\n' character in Multiline Editcontrol.

  2. #2
    Join Date
    May 2005
    Posts
    70

    Re: Multiline Edit control

    Use \r\n instead of \n

  3. #3
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: Multiline Edit control

    Why don't you read MSDN?
    Text lines in a multiline control are separated by '\r\n' character sequences.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  4. #4
    Join Date
    Nov 2001
    Location
    Beyond Juslibol
    Posts
    1,688

    Re: Multiline Edit control


  5. #5
    Join Date
    Sep 2003
    Posts
    90

    Re: Multiline Edit control

    You mean to say that ..i will have to loop through the characters in the string
    and insert \r whenever i encounter an '\n' .

  6. #6
    Join Date
    May 2005
    Posts
    70

    Re: Multiline Edit control

    You could do that (Although no looping is required, use CString::Replace()), but if you're reading the information from a file (I'm just guessing here, but it seems to be the case), then you might consider opening that file not in text mode but in binary mode. This way the \r\n (EOLN in Windows ASCII files) will not be substituted by \n when you read from the file.

    Regards.

  7. #7
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: Multiline Edit control

    If you are reading text from a file, use CStdioFile::ReadString().
    The CString version of this function removes the '\n' if present; the LPTSTR version does not.
    You should do something like this:
    Code:
    CStdioFile file;
    CStirng strText = "";
    if(file.Open("data.txt"))
    {
      CString strLine
      while(file.ReadString(strLine))
         strText += strLine + "\r\n";
    
      file.Close();
    }
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

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