请选择 进入手机版 | 继续访问电脑版

我懂得彩色编程了(Windows)

电脑技术 电脑技术 1533 人阅读 | 6 人回复 | 2022-08-07

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 孤星1 于 2022-8-12 15:32 编辑

B3u8mA.png


Screenshot 2022-08-12 150934.png



一个是用ESC[<n>m 的ANSI代码,一个是直接调用Win32 API, SetConsoleTextAttribute.
我用的是C++. (这里就不放源代码了)

Python好像也是用ANSI代码,其他语言如Visual Basic .NET就比较简单,如:

  1. Console.ForegroundColor = ConsoleColor.Red;
  2. Console.Write("Hello World");
复制代码
你们是如何用你的程序语言在终端窗口显示含彩色的文字?

回答|共 6 个

simonzhd

simonzhd 发表于 2022-8-7 18:38:10| 字数 16 | 显示全部楼层

css里的color属性了解一下

蓝莓糖

蓝莓糖 发表于 2022-8-7 19:01:05| 字数 4 | 显示全部楼层

加油加油

孤星1

孤星1 发表于 2022-8-7 19:14:19| 字数 55 | 显示全部楼层

simonzhd 发表于 2022-8-7 18:38
css里的color属性了解一下

CSS的,我也略知一二,哈哈。

孤星1

孤星1 发表于 2022-8-7 19:14:35| 字数 28 | 显示全部楼层


谢谢鼓励!

孤星1

孤星1 发表于 2022-8-8 15:09:11| 字数 680 | 显示全部楼层

本帖最后由 孤星1 于 2022-8-12 15:32 编辑

B3uMY6.png



  1.     printf("\x1b[48;5;10mWelcome to coloring in Windows.\r\n");
  2.     printf("\x1b[48;5;20mWelcome to coloring in Windows.\r\n");
  3.     printf("\x1b[48;5;30mWelcome to coloring in Windows.\r\n");
  4.     printf("\x1b[48;5;40mWelcome to coloring in Windows.\r\n");
  5.     printf("\x1b[48;5;50mWelcome to coloring in Windows.\r\n");
  6.     printf("\x1b[48;5;60mWelcome to coloring in Windows.\r\n");
  7.     printf("\x1b[48;5;70mWelcome to coloring in Windows.\r\n");
  8.     printf("\x1b[48;5;80mWelcome to coloring in Windows.\r\n");
  9.     printf("\x1b[48;5;90mWelcome to coloring in Windows.\r\n");
  10.     printf("\x1b[48;5;100mWelcome to coloring in Windows.\r\n");
复制代码


console.zip

674 Bytes, 下载次数: 0

蓝莓糖

蓝莓糖 发表于 2022-8-8 15:26:05| 字数 9 | 显示全部楼层

又有新进展了,不错
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则