2

In command prompt, when you press the insert button, the cursor changes from a thin bar to a thicker bar to show that it is in overwrite mode, and when you press it again, it makes it thin again to show that it is in insert mode is there any way to do this in C#?

EDIT: I want to know if there's a way to make the cursor thick/thin, not how to overwrite text

Qwerty01
  • 769
  • 8
  • 25
  • Are you intending to overwrite characters and/or stay on the same line when using Console.Write? If so, there are several ways. http://stackoverflow.com/questions/888533/how-can-i-update-the-current-line-in-a-c-sharp-windows-console-app But is that what you want? Maybe a clearer explanation of what you're trying to do. – Sumo Jul 20 '12 at 05:35
  • i'm trying to be able to make the cursor either thick or thin – Qwerty01 Jul 20 '12 at 06:06

1 Answers1

4

You can use the Console.CursorSize property to change the "thickness" of the cursor.

The above respective MSDN page gives all the information you need, plus an example. Just note one thing though: if you change the cursor size in your application and then exit, it remains at that size, unless you change it explicitly back (or use the CMD window`s properties to do so).

Example (rudimentary to illustrate the point):

public static void Main()
{
    int originalSize = Console.CursorSize;

    try
    {
       Console.CursorSize = 100; // Use "full" cursor
       ...  
    }
    finally 
    {
       // make sure we leave the cursor size as we found it.
       Console.CursorSize = originalSize;
    }
}

Finally, another word of warning: If you redirect the output of your application to a file or a pipe (> or |), the Console.CursorSize property will raise an IOException. Keep that in mind when thinking about how your application will be used.

Christian.K
  • 47,778
  • 10
  • 99
  • 143