Yes I can get the selected text like this.
I am not sure how or if the newline character could be indicated and how it could be a solution.
I have put a messagebox to show what text that is selected. If putting this code inside a richTextBox1 eventhandler and after that write these 2 lines in the box and important start with the second line first and then write the first line.
123456 hello
123456789
When you have written the word: hello then this will be selected and turn blue:
hello
12345
I wonder how this can be prevented as I only trying to select ´hello´ ?
Code:
int positionen = 0;
positionen = richTextBox1->SelectionStart;
char one, two, three, four, five;
if ( richTextBox1->SelectionStart >= 1 ) { one = richTextBox1->Text[positionen - 1];}
if ( richTextBox1->SelectionStart >= 2 ) { two = richTextBox1->Text[positionen - 2];}
if ( richTextBox1->SelectionStart >= 3 ) { three = richTextBox1->Text[positionen - 3];}
if ( richTextBox1->SelectionStart >= 4 ) { four = richTextBox1->Text[positionen - 4];}
if ( richTextBox1->SelectionStart >= 5 ) { five = richTextBox1->Text[positionen - 5];}
if ( richTextBox1->SelectionStart >= 5 )
{
if( one == 'o' && two == 'l' && three == 'l' && four == 'e' && five == 'h' )
{
this->richTextBox1->Select((positionen - 5), positionen);
this->richTextBox1->SelectionColor = Color::Blue;
MessageBox::Show(this->richTextBox1->SelectedText);
}
}