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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
akhil18 reputationPosted Apr 1, 2009, 1:29 AM EDT
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 IlioskiRank #9,295 · 208 reputationPosted Apr 1, 2009, 3:55 AM EDT
akhil18 reputationPosted Apr 1, 2009, 4:02 AM EDT
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 IlioskiRank #9,295 · 208 reputationPosted Apr 1, 2009, 5:50 AM EDT
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# :)