通过进入编辑模式阻止挂起的控制台应用程序

时间:2013-09-23 12:46:39

标签: c# console

我使用下一代码在控制台中打印进度。但是,因为我使用快速编辑模式,如果我在控制台黑色区域内单击,则会出现白色光标并且我的应用程序将被挂起如何防止此类行为继续使用快速编辑模式?

public static void WriteTheSameLine(String message)
{
    Console.CursorLeft = 0;
    int maxCharacterWidth = Console.WindowWidth - 1;
    if (message.Length > maxCharacterWidth)
    {
        message = message.Substring(0, maxCharacterWidth - 3) + "...";
    }
    message = message + new string(' ', maxCharacterWidth - message.Length);
    Console.Write(message);
}

1 个答案:

答案 0 :(得分:4)

非常bottom answer here似乎在解释它。

Your CMD windows is in quick edit mode which automatically enter the edit mode when you click on the screen. The Enter is for copy the text in the white-box and exit the edit mode. Normally CMD only enter edit mode when you right click on the black screen and choose Mark. To change back to normal, right click on the title bar of the windows and choose Properties, select Options tab and deselect "Quick Edit Mode" and click ok.