用C#闪烁文本 [英] Blink text in C#

查看:123
本文介绍了用C#闪烁文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用C#在控制台中闪烁文本?

How do i blink the text in console using C#?

推荐答案

人-b处在正确的轨道上,但是他们的代码需要一些更改:

Person-b was on the right track, but their code needs some changes:

    static void Main()
    {
        string txt = "Hello, world!";
        while (true)
        {
            WriteBlinkingText(txt, 500, true);
            WriteBlinkingText(txt, 500, false);
        }
    }

    private static void WriteBlinkingText(string text, int delay, bool visible)
    {
        if (visible)
            Console.Write(text);
        else
            for (int i = 0; i < text.Length; i++)
                Console.Write(" ");
        Console.CursorLeft -= text.Length;
        System.Threading.Thread.Sleep(delay);
    }

编辑:稍微重构了代码

这篇关于用C#闪烁文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆