none
Problems with object richTextBox

    Question

  • Hello guys,

    i'm with difficults in the hour of copy only a line of the object richTextBox

    For example:

    I have 3 richTexBox in my program and I put a text of 10 lines in richTextBox1 and other in richTextBox2

    I would like of put the first line of richtextBox1 inside of richTextBox3, and then put a first line of richTextBox2 inside of richTextBox3 and successively this way, like in this example:

    richTextBox1 ="um dia\noutro dia\nmais outro dia\n...\n"

    richTextBox2 = "Olá\nTudo bem\nComo vai a família?\n...\n";

    richTextBox3 = "um dia | Olá\noutro dia | Tudo bem\nmais outro dia | Como vai a família?\n...\n";

    I was tried this way, but not working:

    richTextBox3.Text = richTextBox3.Text + richTextBox1.Text + " | " + richTextBox2.Text;

    Help me, please!

    Thursday, April 13, 2017 4:49 PM

Answers

  • Hi Ozzy69,

    Thank you for posting here.

    Here is a simple way for your reference.

      private void button1_Click(object sender, EventArgs e)
            {
                string[] str1 = richTextBox1.Lines;
                string[] str2 = richTextBox2.Lines;
                for (int i = 0; i < str1.Length; i++)
                {
                    richTextBox3.Text += str1[i] + "|" + str2[i] + "\n";
                }
            }

    I hope this would be helpful.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Friday, April 14, 2017 2:52 AM
    Moderator

All replies

  • If the textboxes contain the same number of lines, and formatting is not important, then try this:

    richTextBox3.Lines = richTextBox1.Lines.Zip( richTextBox2.Lines, ( a, b ) => a + " | " + b ).ToArray();

    Thursday, April 13, 2017 6:48 PM
  • Hi Ozzy69,

    Thank you for posting here.

    Here is a simple way for your reference.

      private void button1_Click(object sender, EventArgs e)
            {
                string[] str1 = richTextBox1.Lines;
                string[] str2 = richTextBox2.Lines;
                for (int i = 0; i < str1.Length; i++)
                {
                    richTextBox3.Text += str1[i] + "|" + str2[i] + "\n";
                }
            }

    I hope this would be helpful.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Friday, April 14, 2017 2:52 AM
    Moderator