title: Select text from line A to line B in richtextbox
body: <p><br />
  i'm looking for a way to select text between two lines (A and B) in a richtextbox.
  I tried something like this:</p>
  
  <pre><code>richTextBox1.Select
  (
       richTextBox1.GetFirstCharIndexFromLine(parentesi_inizio[current_idx]),
       (
            richTextBox1.GetFirstCharIndexFromLine(parentesi_fine[current_idx]) -
            richTextBox1.GetFirstCharIndexFromLine(parentesi_inizio[current_idx]) + 1
       )
  );
  </code></pre>
  
  <p>Inside parentesi_inizio and parentesi_fine i have the line number, i should select from line A (parentesi_inizio) to B (parentesi_fine).</p>
  
  <p>After some tests i think the problem is this:</p>
  
  <pre><code>richTextBox1.GetFirstCharIndexFromLine(parentesi_fine[current_idx]) -
  richTextBox1.GetFirstCharIndexFromLine(parentesi_inizio[current_idx]) + 1
  </code></pre>
  
  <p>This code works fine at first, but I noticed that after a while 'begins to show results stoner.</p>
  
  <p>I did further testing and the lines are correct (ie, refer to the right spot) whereas "Select" does not select the entire portion or does it incorrectly (selecting parts that do not have to)</p>
  
  <p>( I used google translate for the last part )</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Imagine this text:</p>
  
  <blockquote>
    <p>Hello <br />
    World || A points here (Line 1) <br />
    Guys! <br />
    This <br />
    is  <br />
    a   || B points here (Line 5) <br />
    line <br /></p>
  </blockquote>
  
  <p>I need to Select (not get text) this text:</p>
  
  <blockquote>
    <p>World <br />
    Guys! <br />
    This <br />
    is  <br />
    a <br /></p>
  </blockquote>
  
  <p>in the richtextbox.</p>
  
  <p>Example images:</p>
  
  <p>Case 1:</p>
  
  <p><img src="https://i.stack.imgur.com/8uGun.png" alt="enter image description here"></p>
  
  <p>Case 2:</p>
  
  <p><img src="https://i.stack.imgur.com/AGVDK.png" alt="enter image description here"></p>
  
  <p>Thats is what i want and what the code i posted do, but after a while the code starts to bug as i said above (at the start).</p>
  
  <p><strong>EDIT 2:</strong></p>
  
  <p>I changed my code to this after varocarbas reply</p>
  
  <pre><code>richTextBox1.Select (
  richTextBox1.GetFirstCharIndexFromLine(parentesi_inizio[current_idx]),
  
  richTextBox1.GetFirstCharIndexFromLine(parentesi_inizio[current_idx])
  + count_length(parentesi_inizio[current_idx], parentesi_fine[current_idx]) );
  </code></pre>
  
  <p>where count_length is</p>
  
  <pre><code>private int count_length(int A, int B)
  {
      // A =&gt; first line
      // B =&gt; last line
  
      int tot = 0;
  
      for (int i = A; i &lt;= B; ++i)
      {
          // read the length of every line between A and B
          tot += richTextBox1.Lines[i].Length - 1;
      }
  
      // return it
      return tot;
  }
  </code></pre>
  
  <p>but now the code not work in every case.. anyway here is a screen of a bugged case using the old code (the code posted at the start of the question)</p>
  
  <p><a href="https://i.stack.imgur.com/VZj9z.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VZj9z.png" alt="wrong"></a><br>
  <sub>(source: <a href="http://picu.site11.com/images/6a70756e35233ae74a9f0722d553cb56a865ea03.png" rel="nofollow noreferrer">site11.com</a>)</sub>  </p>
  
  <p>it select right from the first { but not reach the last } (i do some checks here and the problem is the subtraction not the lines num.)</p>
  
  <p><strong>EDIT 3:</strong></p>
  
  <p>I'm ready sorry varocarbas, i think i just wasted your time.. after see my screen i noticed the problem might be the word wrap i tried to disable it and seems now works ok.. sorry for your time.</p>