Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone,
I am new in programming C#.
I am having a problem with richtextbox,I don't know how to get the text before the text cursor. I have no idea about this. So plz someone help me.
Thx for reading.
sincerely.
Posted

You can get the cursor position indirectly, via the SelectionStart and SelectionLength properties.

The SelectionStart is always the top left of any selected text, and the SelectionLength is the number of character selected.

If there is no selection, you get the current cursor position, and zero. The value is number of characters from the start of the text, so it is simple to work out what characters are before the cursor!
 
Share this answer
 
If there is no selection, you get the current cursor position, and zero. The value is number of characters from the start of the text, so it is simple to work out what characters are before the cursor!<br />

If there is no selection, I will get the current cursor position, and characters before cursor is zero,won't I??
I don't understand.
Sr for my bad English.
Thx for relying me.
Sincerely.
 
Share this answer
 
v2
Thx alot.
I understand ur idea now.
But richtext has method to get the start of aline in Richtext,dosen't it??
sr for my bad skill in programming.
Thx ^^.
 
Share this answer
 
v2
Comments
Santosh K. Tripathi 26-Feb-15 23:32pm    
don't post as solution. you should post a comment.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900