I have created a simple Calendar application and I would like to change the color of names of the days that are displayed. I created a simple condition:
if (nameDay.Text.Equals("Sunday"))
{
daytxt.Foreground = Brushes.Red;
}
But in this case the color is changing permanently. When the name of day changes to "Monday" then color of the text is still red but it should be black. How can I fix my issue?
If You want to change the Text color in C++ language There are many ways. In the console, you can change the properties of output. click this icon of the console and go to properties and change color. The second way is calling the system colors.
If you are going to write your program for Windows and you want to change color of text and/or background, use this: SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), attr); Where attr is a combination of values with | (bitwise OR operator), to choose whther you want to change foreground or background color.
An else
condition is missing from your if
statement in order to achieve what you need.
You can do it 1 of 2 ways:
if (nameDay.Text.Equals("Sunday")) { daytxt.Foreground = Brushes.Red; } else { daytxt.Foreground = Brushes.Black; }
Or
daytxt.Foreground = nameDay.Text.Equals("Sunday") ? Brushes.Red : Brushes.Black;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With