how to move a cursor to a specific line in a text box?

  • Thread starter Thread starter Ramsin Savra
  • Start date Start date
R

Ramsin Savra

Hi, I have below code, to move the cursor to a specific line in a text-box
control (I don't want to use RichTextBox) but doesn't work! any suggestions?


int charIndex = 1;
for (int i = 0; i < snpObject.edtTextBody.Lines.Length && i <
iRequestedLineNumber - 1; ++i)
{

charIndex += snpObject.edtTextBody.Lines.Length;

}


snpObject.edtTextBody.Select(charIndex, 0);
 
Once I red over a little trick, you have to set the SelectionStart propriety
equals the text postion to show and use the ScrollToCarret method to show it

TextBox.SelectionStart=300;
TextBox.SelectionLength=0; //To not show a selectioned area
TextBox.ScrollToCarret();
 
Back
Top