Hi,
I have a custom control inheriting from RadRichTextBox.
I modify the document with RadRichTextBox commands, but sometimes, the RadRichTextBox selection is lost when I click on (for example) a colorpicker, a combobox...
So, I memorize selection when my mouse leave control like this :
private void TextArea_MouseLeave(object sender, EventArgs e)
{
if ((SelectionRange)this.Document.Selection.Ranges.First != null)
{
startPositionMemory = ((SelectionRange)this.Document.Selection.Ranges.First).StartPosition;
stopPositionMemory = ((SelectionRange)this.Document.Selection.Ranges.First).EndPosition;
positionMemory = this.Document.Selection.Ranges.First.StartPosition.Location;
}
}
It seems to work well.
Then, I try to set selection just before command executes :
private void TextArea_CommandExecuting(object sender, CommandExecutingEventArgs e)
{
if (this.Document.Selection.Ranges.Count == 0 && startPositionMemory != null && stopPositionMemory != null)
{
this.Document.CaretPosition.SetPosition(positionMemory);
this.Document.Selection.SetSelectionStart(startPositionMemory);
this.Document.Selection.AddSelectionEnd(stopPositionMemory);
}
}
Document.Selection is highlighted, but command does not apply.
What is the problem with this code ?
Thank you for your response !
Michel
I have a custom control inheriting from RadRichTextBox.
I modify the document with RadRichTextBox commands, but sometimes, the RadRichTextBox selection is lost when I click on (for example) a colorpicker, a combobox...
So, I memorize selection when my mouse leave control like this :
private void TextArea_MouseLeave(object sender, EventArgs e)
{
if ((SelectionRange)this.Document.Selection.Ranges.First != null)
{
startPositionMemory = ((SelectionRange)this.Document.Selection.Ranges.First).StartPosition;
stopPositionMemory = ((SelectionRange)this.Document.Selection.Ranges.First).EndPosition;
positionMemory = this.Document.Selection.Ranges.First.StartPosition.Location;
}
}
It seems to work well.
Then, I try to set selection just before command executes :
private void TextArea_CommandExecuting(object sender, CommandExecutingEventArgs e)
{
if (this.Document.Selection.Ranges.Count == 0 && startPositionMemory != null && stopPositionMemory != null)
{
this.Document.CaretPosition.SetPosition(positionMemory);
this.Document.Selection.SetSelectionStart(startPositionMemory);
this.Document.Selection.AddSelectionEnd(stopPositionMemory);
}
}
Document.Selection is highlighted, but command does not apply.
What is the problem with this code ?
Thank you for your response !
Michel