Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
How to change the visibility of the Cursor of Console in C#
The Console.CursorVisible property in C# allows you to control whether the cursor is visible in the console window. This property accepts a boolean value where true makes the cursor visible and false hides it.
Syntax
Following is the syntax for using the Console.CursorVisible property −
Console.CursorVisible = true; // Makes cursor visible Console.CursorVisible = false; // Hides cursor
To check the current visibility status −
bool isVisible = Console.CursorVisible;
Example - Hiding the Cursor
Let us see an example that demonstrates hiding the cursor −
using System;
class Demo {
public static void Main(string[] args) {
Console.WriteLine("Cursor is initially visible: " + Console.CursorVisible);
// Hide the cursor
Console.CursorVisible = false;
Console.WriteLine("Cursor visibility set to: " + Console.CursorVisible);
Console.WriteLine("Notice that the cursor is now hidden!");
// Show the cursor again
Console.CursorVisible = true;
Console.WriteLine("Cursor is now visible again: " + Console.CursorVisible);
}
}
The output of the above code is −
Cursor is initially visible: True Cursor visibility set to: False Notice that the cursor is now hidden! Cursor is now visible again: True
Example - Console Styling with Hidden Cursor
Here's an example that combines cursor visibility with other console properties −
using System;
using System.Text;
class Demo {
public static void Main(string[] args) {
Console.BackgroundColor = ConsoleColor.Black;
Console.WriteLine("Background color changed = " + Console.BackgroundColor);
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("Foreground color changed = " + Console.ForegroundColor);
Console.InputEncoding = Encoding.ASCII;
Console.WriteLine("Input Encoding Scheme = " + Console.InputEncoding);
Console.OutputEncoding = Encoding.ASCII;
Console.WriteLine("Output Encoding Scheme = " + Console.OutputEncoding);
Console.CursorVisible = false;
Console.Write("Cursor is Visible? " + Console.CursorVisible);
}
}
The output of the above code is −
Background color changed = Black Foreground color changed = White Input Encoding Scheme = System.Text.ASCIIEncoding Output Encoding Scheme = System.Text.ASCIIEncoding Cursor is Visible? False
Common Use Cases
The Console.CursorVisible property is commonly used in scenarios such as −
Menu Systems: Hide the cursor when displaying static menus or selection screens.
Progress Indicators: Hide the cursor during long-running operations to prevent visual distraction.
Game Development: Create cleaner console-based game interfaces by hiding the blinking cursor.
Text Animation: Hide the cursor during text animations or when displaying formatted output.
Conclusion
The Console.CursorVisible property provides simple control over cursor visibility in C# console applications. Setting it to false hides the cursor for cleaner output display, while true restores normal cursor behavior.
