Reputation: 1052
In CSS we're able to edit the text selection's colors by using the ::selection
pseudo-tag. Is it possible, to overwrite the default background color of the selection just for one control, e.g. a RichTextBox? I know, that there is no way to change the default behaviour by something like CSS, but at least overwrite it for this control might be possible.
I already googled for about an hour now, but I only found snippets of syntax highlighting. I want the text to be e.g. yellow instead the typical Windows blue.
EDIT
Like in this fiddle: http://jsfiddle.net/W99Gt/
Upvotes: 2
Views: 3787
Reputation: 6374
In WPF you can accomplish this as follows:
myRichTextBox.SelectionBrush = System.Windows.Media.Brushes.Yellow; // WPF
myRichTextBox.IsInactiveSelectionHighlightEnabled = true;
Unfortunately, the desired behavior is not possible in Windows Forms (details here). The workaround would be to use a WPF RichTextBox in the Windows Form through ElementHost.
References:
TextBoxBase.SelectionBrush Property (WPF)
TextBoxBase.IsInactiveSelectionHighlightEnabled Property (WPF)
EDIT:
Removed the WinForms solution, because SelectionBackColor
does not provide the desired behavior.
Upvotes: 2
Reputation: 19828
There is a property RichTextBox.SelectionColor
which should do the work. Quoting MSDN
A Color that represents the color to apply to the current text selection
Upvotes: 1