blah blah blah is here! blah blah » Close

up0down
link

I want to assign a string the contents of a richtextbox up until the point that the user has selected. Is there a way to do this?

last answered 2 years ago

1 answers

up0down
link

Yes, you can use the textbox' SelectedText property
//Gets the selected text from textBox1
string selected = textBox1.SelectedText;
Hope this helps

up0down
link

I think the OP means that he wants to capture the text <i>before</i> the selection. If that's the case, the code would be:
int index = richTextBox1.SelectionStart;
string priorToSelected = richTextBox1.Text.Substring(0, index);

up0down
link

I see :)

up0down
link

Thanks!

This post was imported from csharpfriends, if you have a similiar question please ask it again.

All previous members have been migrated, hope you enjoy the new platform!

Feedback