1.

How Can You Programmatically Position The Cursor On A Given Line Or On A Character In The Richtextbox Control In C#?

Answer»

The RichTextBox control contains the Lines array property, which displays one item of an array in a separate line. Each line entry has a Length property,

which can be used to accurately position the cursor at a character, as shown in the FOLLOWING code snippet:

PRIVATE void GoToLineAndColumn(RichTextBox RTB, int Line, int COLUMN)

{

 int OFFSET = 0;

 for(int i = 0; i < Line -1 && i < RTB.Lines.Length; i++)

 {

 offset += RTB.Lines[i].Length + 1;

 }

 RTB.Focus();

 RTB.Select(offset + Column, 0);

}

The RichTextBox control contains the Lines array property, which displays one item of an array in a separate line. Each line entry has a Length property,

which can be used to accurately position the cursor at a character, as shown in the following code snippet:

private void GoToLineAndColumn(RichTextBox RTB, int Line, int Column)

{

 int offset = 0;

 for(int i = 0; i < Line -1 && i < RTB.Lines.Length; i++)

 {

 offset += RTB.Lines[i].Length + 1;

 }

 RTB.Focus();

 RTB.Select(offset + Column, 0);

}



Discussion

No Comment Found