public class CustomRichTextBox : RichTextBox
{
private bool _selecting;
public CustomRichTextBox()
{
this.MouseLeftButtonDown += (s, e) =>
{
_selecting = true;
};
this.MouseLeftButtonUp += (s, e) =>
{
this.SelectNone();
_selecting = false;
};
this.KeyDown += (s, e) =>
{
if (e.Key == Key.Shift)
_selecting = true;
};
this.KeyUp += (s, e) =>
{
if (e.Key == Key.Shift)
_selecting = false;
};
this.SelectionChanged += (s, e) =>
{
if (_selecting)
this.SelectNone();
};
}
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
{
base.OnMouseLeftButtonDown(e);
e.Handled = false;
}
protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
{
base.OnMouseLeftButtonUp(e);
e.Handled = false;
}
public void SelectNone()
{
this.Selection.Select(this.ContentStart, this.ContentStart);
}
}