How can I disable the selection highlight of RichTexBox
or TextBox
in my Windows Forms Application as shown in the image.
I need to change selection highlight color from Blue
to White
, because I need to hide selection in TextBox
or RichTextBox
all the time. I tried to use RichTextBox.HideSelection = true
, but it doesn't not work as I expect.
You can handle
WM_SETFOCUS
message ofRichTextBox
and replace it withWM_KILLFOCUS
.In the following code, I've created a
ExRichTextBox
class havingSelectable
property:Selectable
: Enables or disables selection highlight. If you setSelectable
tofalse
then the selection highlight will be disabled. It's enabled by default.Remarks: It doesn't make the control read-only and if you need to make it read-only, you should also set
ReadOnly
property totrue
and itsBackColor
toWhite
.You can do the same for
TextBox
control.