Reputation: 147
I have a RichTextBox in my application to show the user an activity log, this RichTextBox is updated automatically when a new event happens.
So my problem is... one of my coworkers is visually impaired, so I've implemented a way so that when he select a fragment of text, that fragment of text is read loud on speakers... up to here everything is working... but if while he is selecting a text a new event happens and the log is updated, the selected text sometimes is lost or is messed up.
Is there a way to detect when he is selecting text? So I can't stop updating while he select text. (And I don't mean to check if the selected text lenght is higher than 0, because sometimes I'd want to keep text selected and neither I want to check if mouse is down because sometimes he uses shift key + arrows to select text)
Upvotes: 3
Views: 965
Reputation: 197
like Mangist has suggested, you can use the SelectionChanged event and "pause" the updating of the textbox.
or
before you update the textbox, you could run a simple check. for example
if (richTextBox1.SelectedText.Equals(string.Empty)) { update } else { dont update }
Upvotes: 2