Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF - How to Change Mouse Cursor Color

Tags:

wpf

I am trying to change the color of the mouse cursor when it's hovering over a textbox, so that it's easier to see on a dark background.

Mouse cursor color comparison.

I know how to change four things:

  1. Textbox background color (.Background)
  2. Textbox foreground color (.Foreground)
  3. Textbox caret color (.CaretBrush)
  4. Mouse cursor image (Mouse.OverrideCursor or this.Cursor)

I just can't change the mouse cursor color.

I came across a way to completely change the mouse cursor to a custom made cursor in another question someone posted: "Custom cursor in WPF?". But it seems overkill for just wanting to change the color, so that I can actually see where the mouse is.

The mouse cursor color actually changes to white automatically if the textbox has a black background. But does not change automatically if it has a dark background that isn't quite black.

like image 276
XSapien Avatar asked May 06 '16 03:05

XSapien


1 Answers

It's this simple. Try changing the CaretBrush color. See sample code below.

<TextBox Text="This is some random text" CaretBrush="Blue" />

EDIT :

You can't change the color of the mouse color without defining a custom cursor, but you can change it's type. See the example below.

<Grid>
    <TextBox Width="70" Height="20" CaretBrush="IndianRed" Text="TEST">
        <TextBox.Style>
            <Style TargetType="TextBox">
                <Style.Triggers>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter Property="Cursor" Value="Pen" />
                    </Trigger>
                    <Trigger Property="IsMouseOver" Value="False">
                        <Setter Property="Cursor" Value="Arrow" />
                    </Trigger>
                </Style.Triggers>
            </Style>
        </TextBox.Style>
    </TextBox>
</Grid>

If you want to change the cursor type see this post Custom cursor in WPF?

like image 50
ViVi Avatar answered Sep 23 '22 14:09

ViVi