I can’t find a way to determine the caret position in the RTB while i’m selecting text. SelectionStart is not an option.
I want to detect the direction of selection whether its backward or forward. I’m trying to achieve this in SelectionChanged event. Any tips would be appreciated.
EDIT:
I solved it by registering mouse movement direction (X axis) with mouseDown and mouseUp events.
Code:
bool IsMouseButtonPushed = false;
int selectionXPosition = 0, sDirection=0;
private void richTextBox_SelectionChanged(object sender, EventArgs e)
{
if (sDirection==2)//forward
{
//dosomething
}
}
private void richTextBox_MouseMove(object sender, MouseEventArgs e)
{
if (IsMouseButtonPushed && (selectionXPosition - e.X) > 0)//backward
{
sDirection = 1;
}
else if (IsMouseButtonPushed && (selectionXPosition - e.X) < 0)//forward
{
sDirection = 2;
}
}
private void richTextBox_MouseDown(object sender, MouseEventArgs e)
{
IsMouseButtonPushed = true;
selectionXPosition = e.X;
}
private void richTextBox_MouseUp(object sender, MouseEventArgs e)
{
IsMouseButtonPushed = false;
}
What are other ways to do it?
SelectionStart and SelectionLength properties changes during left side selection and SelectionLength changes during right side selection.
Simple solution:
Controls:
RitchTextBox + 2xLabels