Step 2 We set the ForegroundColor, which is the text color. We set it to white to have light-colored text.
Step 3 The ResetColor subroutine changes the color scheme (both foreground and background) to the default.
' Step 1: set background to blue.
Console.BackgroundColor = ConsoleColor.Blue
' Step 2: set foreground to white.
Console.ForegroundColor = ConsoleColor.White
' Step 3: write some text, and reset the colors.
Console.WriteLine("White on blue.")
End ModuleWhite on blue.
Different color example. Many colors are available in .NET. We can use bright red with Console.Red to signify a concerning error or warning.
' Set Foreground and Background colors.' ... You can just set one.
Console.ForegroundColor = ConsoleColor.Red
Console.BackgroundColor = ConsoleColor.DarkCyan
' Reset the colors.
Summary. Though it will not be the same as a native Windows Forms program, a console program with colors is often more enjoyable to use than one without colors.
Dot Net Perls is a collection of tested code examples. Pages are continually updated to stay current, with code correctness a top priority.
Sam Allen is passionate about computer languages. In the past, his work has been recommended by Apple and Microsoft and he has studied computers at a selective university in the United States.