none
How to change the cursor colour RRS feed

  • Question

  • hopefully this is a real easy one...  how do you change the blinking cursor colour in a text box from the default black colour? 
    Purkiss
    Friday, October 31, 2008 3:23 PM

Answers

  • I discovered the answer to my question in a blog.

    It turns out I was using incorrect terminology--What I was looking to change was the system caret.  Changing the caret's colour can be done by specifying transparent black as the text box's background so that the system will display the inverse of that colour--white.

    This sounds simple but its not so since we do not make it public. So what are the options we have here. hmmm... How about an hack J. The caret color is the inverse of the background color. So a very simple way is to set the background which then doesn’t get rendered.

    <Style TargetType="{x:Type TextBox}">
                <Setter Property="KeyboardNavigation.TabNavigation" Value="None" />
                <Setter Property="FocusVisualStyle" Value="{x:Null}" />
                <Setter Property="AllowDrop" Value="true" />
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type TextBox}">
                            <Grid>
                                <Border x:Name="Border” BorderThickness="2"  SnapsToDevicePixels="True"  Padding="2" CornerRadius="2">
                                    <ScrollViewer Margin="0" x:Name="PART_ContentHost" Style="{DynamicResource SimpleTextScrollViewer}"  />
                                </Border>
                            </Grid>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsEnabled" Value="False">
                                    <Setter Property="Background" Value="{DynamicResource DisabledBackgroundBrush}" TargetName="Border" />
                                    <Setter Property="BorderBrush" Value="{DynamicResource DisabledBackgroundBrush}" TargetName="Border" />
                                    <Setter Property="Foreground" Value="{DynamicResource DisabledForegroundBrush}" />
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

    Now if you have a TextBox with the Background set to Red you would have the white background but the caret is Cyan. Yoohoo!!!. Notice the missing background property on the Border. Its not being set. That’s where the magic lies.

    If you are not creating a new style then you could change the default template of the textbox and remove the background property on the Border.. voila!! … The same trick applies to RichTextBox. You can get the default style from Expresson blend, Snoop tool, or from XamlPadX. And


    Source: http://blogs.msdn.com/llobo/archive/tags/Programming/default.aspx  Credit:  Lester's WPF Blog


    Purkiss
    • Marked as answer by Purkiss Wednesday, December 3, 2008 4:03 PM
    Wednesday, December 3, 2008 4:02 PM

All replies

  • Ok--i thought this one would be easy...  no answers here, and my google searches turn up nothing.  Can anyone help?
    Purkiss
    Thursday, November 20, 2008 3:43 PM
  • This is a system parameter, and is not easy to change. This is a quesiton better asked on the platform (Silverlight or WPF) forums. Also, please be clear on whether you are trying to build a Silverlight or WPF application.

    Thanks,
    Unni
    Sunday, November 23, 2008 9:49 PM
    Moderator
  • Hi Unni,

    It's a WPF application.  Thank you for your help--I'll post in the WPF forum!
    Purkiss
    Monday, December 1, 2008 7:09 PM
  • I discovered the answer to my question in a blog.

    It turns out I was using incorrect terminology--What I was looking to change was the system caret.  Changing the caret's colour can be done by specifying transparent black as the text box's background so that the system will display the inverse of that colour--white.

    This sounds simple but its not so since we do not make it public. So what are the options we have here. hmmm... How about an hack J. The caret color is the inverse of the background color. So a very simple way is to set the background which then doesn’t get rendered.

    <Style TargetType="{x:Type TextBox}">
                <Setter Property="KeyboardNavigation.TabNavigation" Value="None" />
                <Setter Property="FocusVisualStyle" Value="{x:Null}" />
                <Setter Property="AllowDrop" Value="true" />
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type TextBox}">
                            <Grid>
                                <Border x:Name="Border” BorderThickness="2"  SnapsToDevicePixels="True"  Padding="2" CornerRadius="2">
                                    <ScrollViewer Margin="0" x:Name="PART_ContentHost" Style="{DynamicResource SimpleTextScrollViewer}"  />
                                </Border>
                            </Grid>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsEnabled" Value="False">
                                    <Setter Property="Background" Value="{DynamicResource DisabledBackgroundBrush}" TargetName="Border" />
                                    <Setter Property="BorderBrush" Value="{DynamicResource DisabledBackgroundBrush}" TargetName="Border" />
                                    <Setter Property="Foreground" Value="{DynamicResource DisabledForegroundBrush}" />
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

    Now if you have a TextBox with the Background set to Red you would have the white background but the caret is Cyan. Yoohoo!!!. Notice the missing background property on the Border. Its not being set. That’s where the magic lies.

    If you are not creating a new style then you could change the default template of the textbox and remove the background property on the Border.. voila!! … The same trick applies to RichTextBox. You can get the default style from Expresson blend, Snoop tool, or from XamlPadX. And


    Source: http://blogs.msdn.com/llobo/archive/tags/Programming/default.aspx  Credit:  Lester's WPF Blog


    Purkiss
    • Marked as answer by Purkiss Wednesday, December 3, 2008 4:03 PM
    Wednesday, December 3, 2008 4:02 PM
  • What I need to change is the white pointer/arrow that I move around the screen using my mouse or touchpad.  My old eyes cannot focus on the white arrow against the white background much of the time.  I spend a lot of time just trying to locate the pointer arrow on the screen my moving it to the upper most corner against a gray background and then moving it to the location I need.  Ridiculous waste of time.  I am hoping I can just change the pointer/arrow to a bright color so it is always obvious where it is located on the screen.

    This has little to do with text boxes and almost 100% to do with settings I hope.

    • Edited by PatSea7 Tuesday, July 17, 2018 6:06 PM
    Tuesday, July 17, 2018 6:04 PM
  • First of all, you are s-o-o asking this in the wrong place. The last post to the thread was TEN YEARS AGO, and the thread (and forum) has nothing to do with your issue.

    I'm guessing that a Google search brought you here and you're asking in a forlorn hope that someone might have an answer. Well, here you go (Windows 10)...

    In the Search bar at the left of the Taskbar, type"Se," which should bring up "Settings" highlighted at the top. Press "Enter." Now click "Ease of Access," then click "Cursor and Pointer Size." Now you can make the cursor larger if you wish, and change its color to black. Up above that, you can also make the text cursor (the vertical "I-beam" cursor when hovering text) thicker if you wish.

    Oh, and in the future, to quickly find the cursor when you're not sure where it is, here's a little setting that makes it easy. In the Search bar again, type "co," which should put "Control Panel" at the top. Press "Enter," then select "Mouse," and then select the "Pointer Options" tab. Down at the bottom, check the "Show location of pointer when I press the CTRL key" box.

    Now, anytime you've lost the cursor, just press either CTRL key and an animated circle will show you exactly where it is located. On the "Pointers" tab, you can also turn on a shadow for the pointer and text cursor, which may or may not improve their visibility for you. So, there you go, 100% to do with settings. That should get you hooked up...  ;-)

    cheers,
    scott


    Please remember to "Mark as Answer" the responses that resolved your issue. It is common courtesy to recognize those who have helped you, and it also makes it easier for visitors to find the resolution later.

    Saturday, July 21, 2018 10:08 PM