Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide caret in WPF TextBox

Is there a way to hide the cursor in a WPF textbox? I know there is Cursor="None" but that only affects the mouse cursor. I want to hide the "text cursor".

like image 990
Brent Lamborn Avatar asked Oct 11 '10 20:10

Brent Lamborn


2 Answers

Caret is the current insert position in a text editor. Cursor is the shape of the mouse cursor.

There is no way to disable the caret in a read-write TextBox. Instead, change the CaretBrush to be transparent.

TextBox txt = ...;
// Hide the caret.
txt.CaretBrush = new SolidColorBrush(Color.FromArgb(0, 0, 0, 0));
// Show the caret.
txt.CaretBrush = null;  // use default Brush
like image 197
kevinarpe Avatar answered Sep 20 '22 18:09

kevinarpe


You can colour the cursor the same colour as the background or Transparent using the TextBox.CaretBrush property.

like image 27
Sheridan Avatar answered Sep 18 '22 18:09

Sheridan