Click here to Skip to main content
15,886,422 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I am finding it difficult if not impossible to find a solution to how i would change the text selection colour in a TextBox control.

I have read that the TextBox control is a thin wrapper around the old windows text box and is therefore more difficult to paint. I found an application when i could hide the background however still cannot customise the selection color =/

Is there any way i can achieve a custom selection colour? Is there a Win32 call that would allow me to do this or any other possibility.

Any pointers would be helpful

Thanks in Advance George
Posted
Updated 24-Feb-12 0:55am
v2
Comments
grwithey 29-Feb-12 4:54am    
If anyone knows of a way of disabling the system text highlight colour i could implement my own technique for highlighting the text in a different color

1 solution

Have you tried
C#
txtTextBox.ForeColoe = Color.Red;


If So then you have to replace your textbox with RTB(rich Text Box).

You will able to achieve what you are trying to achieve here.
 
Share this answer
 
Comments
grwithey 24-Feb-12 7:05am    
I was trying to change the color of the rectangle behind the text when the text is selected. It currently uses the system default as i am aware this is its standard implementation, however i am looking to customise this without having to use the richTextBox control.
Aniket Yadav 24-Feb-12 7:28am    
Ok Then Change the Backcolor of the textbox

txtTextBox.BackColor = Color.Red;

Try this
grwithey 29-Feb-12 3:42am    
Thanks but it is not that rectangle either. It is the highlight applied, (Usually blue behind text in windows)
Member 12284620 24-Sep-19 13:53pm    
I would say the only option is somehow get the bounds of the selection rectangle (in the form of a System.Drawing.Rectangle, then also get the graphics object of the control, then FillRectangle and Draw the text right after that using the color you want. It might be a hack but I think that is how TextBox does it in OnPaint or something like that.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900