Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Problem with a multiline textbox

Problem with a multiline textbox

Scheduled Pinned Locked Moved C#
helphtmlquestion
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    Zeokat
    wrote on last edited by
    #1

    First, the code that i´m using:

    //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. :)

    E 1 Reply Last reply
    0
    • Z Zeokat

      First, the code that i´m using:

      //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. :)

      E Offline
      E Offline
      Eslam Afifi
      wrote on last edited by
      #2

      Nothing is wrong with the TextBox. It's just the string you're getting get from the response is not formatted, the textbox outputs it as it is. Most, if not all, compilers and interpreters don't generate formatted response. If you're calling a static webpage, it's just the way it is.

      Eslam Afifi

      Z 1 Reply Last reply
      0
      • E Eslam Afifi

        Nothing is wrong with the TextBox. It's just the string you're getting get from the response is not formatted, the textbox outputs it as it is. Most, if not all, compilers and interpreters don't generate formatted response. If you're calling a static webpage, it's just the way it is.

        Eslam Afifi

        Z Offline
        Z Offline
        Zeokat
        wrote on last edited by
        #3

        Ok, and how can i format the response because if i see the html of google.com into firefox it appears formatted, but into my textbox no. Any idea how can i output the html source formatted into a textbox?? Thanks in advance. :)

        E 1 Reply Last reply
        0
        • Z Zeokat

          Ok, and how can i format the response because if i see the html of google.com into firefox it appears formatted, but into my textbox no. Any idea how can i output the html source formatted into a textbox?? Thanks in advance. :)

          E Offline
          E Offline
          Eslam Afifi
          wrote on last edited by
          #4

          You'll have to format it yourself. Google and see if someone wrote something you can use or code it yourself. Do NOT use the method where you put the html in xml and output it formatted simply because html can be not well formatted xml.

          Eslam Afifi

          Z 1 Reply Last reply
          0
          • E Eslam Afifi

            You'll have to format it yourself. Google and see if someone wrote something you can use or code it yourself. Do NOT use the method where you put the html in xml and output it formatted simply because html can be not well formatted xml.

            Eslam Afifi

            Z Offline
            Z Offline
            Zeokat
            wrote on last edited by
            #5

            Mmmz... using a richtextbox instead a textbox seems that solve the problem. Thanks for the replies. :)

            E 1 Reply Last reply
            0
            • Z Zeokat

              Mmmz... using a richtextbox instead a textbox seems that solve the problem. Thanks for the replies. :)

              E Offline
              E Offline
              Eslam Afifi
              wrote on last edited by
              #6

              You're welcome. The problem was that the TextBox uses the Environment.NewLine while the RichTextBox uses any of '\n' and '\r' too as line breaks. I didn't know that, thanks for the info.

              Eslam Afifi

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups