I would like to get the selected text from the rich text box.
When I drag a selection in the ui and then query the selected text I get an empty string:
If I use the Document.CaretPosition to set the selection to the beginning and end of the word, the GetSelectedText() returns that selected word. However, that is just the word under the caret - not necessarily all of the selected words.
My questions:
thank you
When I drag a selection in the ui and then query the selected text I get an empty string:
var thisIsEmpty = rtb.Document.Selection.GetSelectedText()
If I use the Document.CaretPosition to set the selection to the beginning and end of the word, the GetSelectedText() returns that selected word. However, that is just the word under the caret - not necessarily all of the selected words.
MainMessageBodyTextBox.Document.Selection.SetSelectionStart(cpos);
cpos.MoveToCurrentWordEnd();
MainMessageBodyTextBox.Document.Selection.AddSelectionEnd(cpos);
text = MainMessageBodyTextBox.Document.Selection.GetSelectedText();
My questions:
- why is the initial selection empty when dragged from the ui (my document is ReadOnly, but changing that didn't seem to make a difference)
- how can I retrieve all of the selected words from the Selection (the words will be contiguous)
thank you