Hi Everyone !!
How can I set the position of the I beam in richTextBox at for example (line 14, column 5)?? or select the word that starts at line 14, column 5??
Hi Everyone !!
How can I set the position of the I beam in richTextBox at for example (line 14, column 5)?? or select the word that starts at line 14, column 5??
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
akhilPosted Apr 1, 2009, 5:29 AM
richTextBox1.SelectionStart=GetSelectionStart(5,3)
richTextBox1.SelectionLength=10
'to set cursor to specific line just pass 0 in column no and set seletionlength to 0
Public Function GetSelectionStart(nLine as Integer,nColumn as Integer ) As integer
Dim nIndx As Integer
Dim nSelectionIndex as Integer=0
Dim sLines() As String =richTextBox1.Lines
For nIndx=0 To sLines.Length -1
nSelectionIndex+=sLines(nIndx).Length
Next
return nSelectionIndex+nColumn
End Function
Aleksandar IlioskiPosted Apr 1, 2009, 9:50 AM
Thank you one more time, i also rewrite it in c# with some modification, so it can throw exception if you try to select something in empty line...
public
int SetPosition(int linija, int kolona){
int doKade = 0; string[] lini = richTextBox1.Lines; if (lini[linija-1].Length == 0){
throw new Exception("Empty line");}
for (int i = 0; i < linija -1; i++){
doKade += lini[i].Length+1;
}
return doKade + kolona;}
This was realy good piece of code, thank you for shearing it with me. It made me to learn litle VB so I can rewrite it in c# :)
akhilPosted Apr 1, 2009, 8:02 AM
richTextBox1.SelectionStart=GetSelectionStart(5,3);
richTextBox1.SelectionLength=10;
//to set cursor to specific line just pass 0 in column no and set seletionlength to 0
public int GetSelectionStart(int nLine ,int nColumn )
{
int nIndx ;
int nSelectionIndex =0;
string [] sLines=richTextBox1.Lines;
for(nIndx=0;nIndx<sLines.Length ;nIndx++)
{
nSelectionIndex+=sLines[nIndx].Length;
}
return nSelectionIndex+nColumn;
}
Aleksandar IlioskiPosted Apr 1, 2009, 7:55 AM