Question RichTextBox - Color Control

JaedenRuiner

Well-known member
Joined
Aug 13, 2007
Messages
340
Programming Experience
10+
Well,

At first I saw the property "SelectionBackColor" and "SelectionColor" but they don't seem to conform to how I'd want them to. Basically, I have manually set the colors (Fore & Back) of the control to initiate the default colors, as this is a SQL source input control on my form (and eventually i'll be doing some syntax highlighting) however, given the current colors of my control, when I select text, the selection background is barely a shade off my current background, which makes it a bit...difficult to see.

So I thought (given my background is Color.DarkBlue) to make my SelectionBackColor Color.Yellow. But it didn't work. When I select text it is still using the System.Highlight color. How can I define the "Global - This will be the SelectionBackground Color from here on out no matter what idiot idea gets into your head otherwise". :D

It appears from this the only way I can do the SelectionBackColor to work the way I want to, I have to listen for the moment any text is selected and then set the BackColor once the text is selected. I want to "pre-define" this value for "future selections" (if that is even possible)

Thanks
 
"System.Highlight color" is as you indicate a system setting, in control panel "Window Color and Appearance" they call it in Vista. SelectionBackColor is also as you figured out used to apply color to current selection.
 
I already understand that. I'm asking is there a built-in way to Set the RichTextBox's "Default Highlight Color" so I don't always have to listen for the Selection Changed event and keep changing the selection back color.

Basically, I know the SelectionBackColor or HighlightColor will ALWAYS be yellow for that control. is the only way to affect that change:
VB.NET:
private sub RichText_SelectionChanged() handles RichText.SelectionChanged
DirectCast(Sender, RichTextBox).SelectionBackColor = Color.yellow
end sub

Thanks
 
The highlighting that occurs when making a selection and setting static backcolor for that selection are two different things. I'm not aware of other way to change the dynamic highlighting color than changing the system color scheme. Regarding SelectionChanged I don't understand what you are trying to achieve. Selection changes all the time, even just moving the caret around counts as selection changes (sel.length=0).
 
VBExpress

The IDE itself. You can go to Tools | Options | Environment |Fonts & Colors. In the Text Editor section there is an Item:

"Selected Text" where you can select Foreground and Background colors.

Now, Every time I select a word/character/block of text in the Text Editor the VBExpress IDE does not use the Windows System "Highlight" or "Highlighted Text" colors, it is using the colors I defined for it in the Options.

I want the same behavior. I want to say: For Selections Use These Colors.

Thanks
 
Who knows how they do it, they may perhaps not be using a RTB control but instead drawing all that stuff.
I find nothing about this when searching, but I found a dwEffects flag for CHARFORMAT2 structure called CFE_AUTOBACKCOLOR that sounded tempting, maybe you could find more information about it?
 
Back
Top