locked
How to change highlighting color of textbox control? RRS feed

  • Question

  • hi,
    is it possible to change the selection color of a textbox control?
    by default, when i select a text within textbox, the color of the background turns to light blue.
    how can i change this? or is this defined by system?
    or is it possible to create a customized textbox control where the highlight color can be changed?

    thanks,
    bkohler
    Tuesday, November 14, 2006 4:34 PM

Answers

  • this is a feature that we will consider for future releases. Thanks for the feedback

     

    Wednesday, May 21, 2008 8:04 PM
  • WPF 4 provides it: http://blogs.msdn.com/text/archive/2009/08/28/selection-brush.aspx
    Tuesday, September 29, 2009 10:01 AM
  • currently we dont allow changing the selection color... this is determined by the system settings
    Tuesday, November 14, 2006 8:12 PM
  • selection highlight color can now be set using the selection brush.. you could use the beta1 bits to try it out

    vertical text rendering is still unsupported.
    Tuesday, September 29, 2009 3:38 PM

All replies

  • currently we dont allow changing the selection color... this is determined by the system settings
    Tuesday, November 14, 2006 8:12 PM
  • thanks for the information,

    is it possible to create a my own TextBox control where i define such a property? are there any other input field controls, besides the TextBox and the RichTextBox where i can type in text?
    how can create i create my own control where i can type in some text?

    thanks,
    bkohler

    Wednesday, November 15, 2006 8:20 AM
  • I had to workarround this problem due to the design of a machine application
    I solved the problem by changing in code the Highlightext System Color.
    You must ensure to reset back the default color the when the application ends.
    I hope that their will be a Property for the selected color in Textboxes in the future.
    A sample can be downladed here at www.sp-systems.ag/download/vb/highlight.zip

    Wednesday, November 29, 2006 2:26 PM
  •  MartinWassmer wrote:

    I had to workarround this problem due to the design of a machine application
    I solved the problem by changing in code the Highlightext System Color.
    You must ensure to reset the default color the application ends.
    I that their will be Property selected color in Textboxes in the future.
    A sample can be downladed here at www.sp-systems.ag/download/vb/highlight.zip



    using the win32 API which is exposed by user32.dll module doesn't help either, because unlike Winforms' TextBox control, WPF's TextBox is not a wrapper around win32 text editing control, WPF's TextBox control is built from ground up, this also holds true to other WPF controls.

    Sheva
    Wednesday, November 29, 2006 3:11 PM
  • It seems that WPF's TextBox uses the SystemColors.HighlightBrushKey internally as the highlight color, so SetSysColor should effect the value of SystemColors.HighlightBrushKey, which means the SetSysColor trick does work in this scenario, sorry for my previous post.

    Sheva
    Wednesday, November 29, 2006 3:40 PM
  • hi,

    since i don't want to change the the text highlight color in all applications on my machine, the SetSysColor trick does not work for me. My wish is to change the text highlight color only within my applications.
    Developing a TextBox from scratch (inherited from System.Windows.Controls.Control) seems to be quite complex. I checked the TextBox control which inherits from TextBoxBase with the .NET Reflector. To me it is even not possible to develop my own TextBox control inherited from TextBoxBase.
    A complete new implemenation of a TextBox control seems to be quite work intensive.
    Any ideas?

    bkohler




    Thursday, November 30, 2006 2:36 PM
  • I tried setting the system key color SystemColors.HighlightBrushKey :

    Code Snippet

    <Style.Resources>
                            <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="LightGreen"/>
    </Style.Resources>



    but it does not work.


    Can you please confirm that change the highlight color is not possibile with standard TextBox implementation? Do I need to rewrite the control?
    Monday, February 25, 2008 8:21 AM
  •  

    "currently we dont allow changing the selection color... this is determined by the system settings" 

     

    Will this be availible in the future?  The current highlight is not very noticeable on a dark background and it is nice to be able to change the color.  Changing the system color is not going to work.

    Wednesday, May 21, 2008 6:52 PM
  • this is a feature that we will consider for future releases. Thanks for the feedback

     

    Wednesday, May 21, 2008 8:04 PM
  • The SP1 has been released since some weeks. Any news regarding this topic? Did you plan it for SP2 or do you have any workaround?


    Thursday, October 30, 2008 4:40 PM
  • Creating your TextBox control isn't that hard really. I've done it several times in C++ using gdi and the win32 api... I even managed to implement some HTML syntax highlighting. Unfortunately my laptop crashed a couple of weeks ago :-(

    In C#, take a look at the Graphics class (more specifically the Graphics.DrawString method) and the Graphics.DrawLine to create a caret (may want to take a look at the Timer class to simulate the blink feature of the caret).

    In C++, use DrawText or TextOut and CreateCaret and ShowCaret.

    I don't know about WPF... Never heard of it before :S


    PS: Changing the system color with SetSysColor works like a charm, I tried it once.
    Thursday, January 15, 2009 12:01 PM
  • another feature with regards to me having a similiar situation is i want the selected text to be highlighted even if the textbox looses focus.
    Friday, April 24, 2009 10:45 PM
  • The link here is broken. I mean the link in MartinW28 post above. My comment has dropped to the end for some reason?

    To answer FocusedW0LF, to keep the text highlighted when the textbox looses focus you set the .HideSelection property to false.

    In response to point raised by deXo-fan has anyone written or know of a good implementation of a textbox control that supports 
    (1) vertical text centering and (2) transparent backcolor? (3) Setable selection highlight color


    Tuesday, June 23, 2009 3:31 PM
  • WPF 4 provides it: http://blogs.msdn.com/text/archive/2009/08/28/selection-brush.aspx
    Tuesday, September 29, 2009 10:01 AM
  • selection highlight color can now be set using the selection brush.. you could use the beta1 bits to try it out

    vertical text rendering is still unsupported.
    Tuesday, September 29, 2009 3:38 PM
  • If you don't mind a bit of a hack, it is technically [possible] to do this in 3.5.

    SolidColorBrush current = SystemColors.HighlightBrush;
    FieldInfo colorCacheField = typeof(SystemColors).GetField(“_colorCache”, BindingFlags.Static | BindingFlags.NonPublic);
    Color[] _colorCache = (Color[])colorCacheField.GetValue(typeof(SystemColors));
    _colorCache[14] = Color.FromArgb(0xFF, 0xFF, 0×00, 0×00);



    If the theme settings are changed under you, that probably resets it.  But that seems like a pretty rare case.
    Saturday, December 19, 2009 3:50 AM
  • I found the Framework 4 ability to set selection color to be quite useful in RichTextBox.  By setting it to transparent I was able to implement my own selection by setting background color of text ranges as computed from mouse positions.  This avoids the "word processing" rules by which the RichTextBox sets the selection.
    Wednesday, April 21, 2010 1:55 PM