Problem with a multiline textbox

This is a discussion on Problem with a multiline textbox within the C# Programming forums, part of the General Programming Boards category; First, the code that i´m using: Code: //Get url contents HttpWebRequest hRequest = ((HttpWebRequest)WebRequest.Create(url)); hRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows ...

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    7

    Question Problem with a multiline textbox

    First, the code that i´m using:

    Code:
    //Get url contents
    HttpWebRequest hRequest = ((HttpWebRequest)WebRequest.Create(url));
    hRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; es-ES; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3";
    HttpWebResponse resp = (HttpWebResponse)hRequest.GetResponse();
    
    //Read contents and output into a textbox
    StreamReader reader = new StreamReader(resp.GetResponseStream());
    string res = reader.ReadToEnd().ToString();
    reader.Close();
    textBox1.Text = res;


    The problem is when i see html source into the textbox it appears bad formatted, dont know if each line of a texbox has a limit of characters and this is why it jumps to another line or what happens.
    I set the wordwrap property of the textbox to false and added both scrolls bars, but it still bad formatted.

    Can someone help me?

    Thanks in advance.
    Last edited by Zeokat; 10-19-2008 at 06:14 AM.

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    It could be a bad newline character. Try:
    Code:
    textBox1.Text = textBox1.Text.Replace("\n", "\r\n");
    or:
    Code:
    textBox1.Text = textBox1.Text.Replace("\n", "\n\r");
    (I always forget which order they should be)
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Ex scientia vera
    Join Date
    Sep 2007
    Posts
    478
    Quote Originally Posted by Magos View Post
    It could be a bad newline character. Try:
    Code:
    textBox1.Text = textBox1.Text.Replace("\n", "\r\n");
    or:
    Code:
    textBox1.Text = textBox1.Text.Replace("\n", "\n\r");
    (I always forget which order they should be)
    The first one. \r\n
    "What's up, Doc?"
    "'Up' is a relative concept. It has no intrinsic value."

  4. #4
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    bump

  5. #5
    Registered User
    Join Date
    Oct 2008
    Posts
    7
    Thanks for the info.

    Problem solved now.

    Another choice is use a richtext box, works perfect.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 10:22 AM
  2. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  3. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  4. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  5. beginner problem
    By The_Nymph in forum C Programming
    Replies: 4
    Last Post: 03-05-2002, 04:46 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21