8

So I'm trying to find a simple code that makes my code get printed in bold. When I searched the internet all of them were so complicated that it wasn't even worth it. Is there any easier way to make a string or just a Console.WriteLine(" "); bold?

Console.Write("Type in the number of people to create: ");
int time = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("\nGenerating " + time + " people please stand by...");
System.Threading.Thread.Sleep(3000);
Console.Clear();
ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86
user12929842
  • 123
  • 1
  • 4
  • 4
    Have you ever seen bold text on a console app? – TheGeneral Feb 20 '20 at 05:05
  • 2
    Well... I didn't know what a console app even was until 2 days ago – user12929842 Feb 20 '20 at 05:07
  • 4
    You cant do it in any *meaningful sense*, in short you should focus on other things, change the *color* (it will have the same effect) it will make you feel just as good – TheGeneral Feb 20 '20 at 05:10
  • for people saying console formatting is not a thing, check my github, same username, there is a repo names work-logs, I have console formatting in Python. You can do basics like colors and bold underline etc. If you have seen the errors in red in any console then you should know it is possible. (I first noticed it is possible when installing ruby in windows. because of selective coloured texts) – Atreyagaurav Feb 20 '20 at 05:20

3 Answers3

8

You can use the ANSII escape codes, as long as your console supports it.

You can do basics like, color text, background and bold,underline and reverse colors. for example in c#

Console.WriteLine("\x1b[1mTEST\x1b[0m");

will print it in bold. \x1b[0m at the end is used to reset the formatting, many formatting options are made by changing the number after the bracket.

look into these links, I have used it with C and Python in bash, but I'm not sure about C# at the moment.

https://www.jerriepelser.com/blog/using-ansi-color-codes-in-net-console-apps/

ANSI-Coloring Console Output with .NET

This link has all the codes for ANSII escape codes, I have used it in C, so It may need some modifications.

http://www.lihaoyi.com/post/BuildyourownCommandLinewithANSIescapecodes.html

Leniel Maccaferri
  • 100,159
  • 46
  • 371
  • 480
Atreyagaurav
  • 1,145
  • 6
  • 15
  • 2
    It is not bold for me. – Yola Oct 02 '21 at 02:36
  • @Yola Which language are you coding in, and does your console support ANSII escape sequences? – Atreyagaurav Oct 02 '21 at 22:18
  • C# in VS. It makes the test white instead of gray. But not bold. Maybe you can add image? – Yola Oct 03 '21 at 11:26
  • Depending on the qualities of your console, bright could be taken for bold which in turn could be taken for less grey ¯\_( ͡❛ ͜ʖ ͡❛)_/¯ – Onno van der Zee Feb 17 '22 at 20:40
  • @Yola Sorry i can't add images with tests on C#, as I no longer use it. I use bash shell and all ancii escape sequences work for me, but I don't think my screenshot will be useful for comparison purposes. – Atreyagaurav Feb 18 '22 at 16:12
1

Fonts and Styles are not available on a per-word basis.(@Atreyagaurav)

But You Can Set Console.ForegroundColor

Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("This Is A Test Txt"); // Print Text In Red Color
Console.ResetColor(); 

Or Alternatively, You Can Change cmd Font Setting

cmd Setting

alirzasahb
  • 137
  • 2
  • my question is does it change the color for the whole console? or just the one line or WriteLine? right now I can't test it. If it changes the whole console color then there isn't much point. – Atreyagaurav Feb 20 '20 at 09:11
  • @Atreyagaurav It Change the color for the whole console but you can write what you want in specific color and then use Console.ResetColor() or Console.ForegroundColor = ConsoleColor.White to reset default console foreground color – alirzasahb Feb 20 '20 at 11:09
0

Fonts and Styles are not available on a per-word basis. To get bold, italics, underline or size, you would have to change all text in the Console.

But you can set the Console.ForegroundColor, Console.BackgroundColor

Rakin
  • 1,271
  • 14
  • 30