Quantcast
Channel: Windows Forms General forum
Viewing all articles
Browse latest Browse all 12583

How can i add a new line to richTextBox ?

$
0
0

I have this code:

richTextBox1.Invoke((MethodInvoker)delegate
            {
                ColorText.AppendText(richTextBox1, "Server: ", Color.Green);
                ColorText.AppendText(richTextBox1, server+"          ", Color.Red);
                ColorText.AppendText(richTextBox1, "Port: " + port, Color.Green);
                ColorText.AppendText(richTextBox1, port.ToString(), Color.Red);
            });
            if (!sock.Connected)
            {
                Console.WriteLine("Failed to connect!");
                return;
            }
            input = new System.IO.StreamReader(sock.GetStream());
            output = new System.IO.StreamWriter(sock.GetStream());

             //Starting USER and NICK login commands 
         output.Write(
            "USER " + nick + " 0 * :" + owner + "\r\n" +"NICK " + nick + "\r\n"
         );
         output.Flush();

         //Process each line received from irc server
         //buf = input.ReadLine();
         while ((buf = input.ReadLine()) != null)
         {
             buf = buf + Environment.NewLine;
             //Display received irc message
             //Console.WriteLine(buf);
             richTextBox1.Invoke((MethodInvoker)delegate
             {
                 ColorText.AppendText(richTextBox1, buf,Color.Red);
             });


First im adding some text to the richTextBox then inside the while loop im adding a new line and then adding more text to the richTextBox.

The result in the richTextBox is:

Server: chat.eu.freenode.net Port: 66676667:cameron.freenode.net NOTICE * :*** Looking up your

hostname... :cameron.freenode.net NOTICE * :*** Found your hostname

The Server: chat.eu.freenode.net          Port: 6667 should be in one line then a new empty line and then in the next third line to start the new text  6667:cameron.freenode.net NOTICE....

But this part :cameron.freenode.net NOTICE is like a continue of the other part and not a from a new line.

I want that between Port: 6667 and 6667:cameron....there will be one line space.

It should be like:

Server.......Port.....

6667:cameron.....

I did:

buf = buf + Environment.NewLine;

So the text is in lines but it didnt help my problem.


Viewing all articles
Browse latest Browse all 12583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>