public void colored_print(dynamic input, string TextColor, string BackgroundColor, bool endchar, bool centertext) { ConsoleColor text; ConsoleColor background; ConsoleColor.TryParse(TextColor, out text); ConsoleColor.TryParse(BackgroundColor, out background); Console.ForegroundColor = text; Console.BackgroundColor = background; if (endchar == true) { if (centertext == true) { Console.WriteLine(String.Format("{0," + Console.WindowWidth / 2 + "}", input)); } Console.WriteLine(input); } else { if (centertext == true) { Console.Write(String.Format("{0," + Console.WindowWidth / 2 + "}", input)); } Console.Write(input); } Reset(); }
public void changeBackground(string BackgroundColor) { ConsoleColor background; ConsoleColor.TryParse(BackgroundColor, out background); Console.BackgroundColor = background; }
public void changeForeground(string ForegroundColor) { ConsoleColor foreground; ConsoleColor.TryParse(ForegroundColor, out foreground); Console.ForegroundColor = foreground; }
private ConsoleColor _getConsoleColor(string path) { var reader = new SettingsReader(); return(ConsoleColor.TryParse( reader.GetStringSettings(path), true, out ConsoleColor color) ? color : ConsoleColor.Black); // If value cannot be parsed, black is returned. }
public override ExecutionContext VisitColorier(Cosmos.ColorierContext context) { var dark = ""; var translatedColor = ""; if (context.dark != null) { dark = "Dark"; } if (context.blue != null) { translatedColor = "Blue"; } else if (context.green != null) { translatedColor = "Green"; } else if (context.red != null) { translatedColor = "Red"; } else if (context.white != null) { translatedColor = "White"; } else if (context.black != null) { translatedColor = "Black"; } else { throw new UnHandledColorException("La couleur indiquée n'est pas encore prise en charge"); } var newColor = ConsoleColor.Gray; bool parse = ConsoleColor.TryParse($"{dark}{translatedColor}", out newColor); if (parse) { if (context.background != null) { executionConsole.SetBackColorTo(newColor.ToString()); } else { executionConsole.SetFrontColorTo(newColor.ToString()); } } return(null); }
/// <summary> /// Writes out a line with color specified as a string /// </summary> /// <param name="text">Text to write</param> /// <param name="color">A console color. Must match ConsoleColors collection names (case insensitive)</param> public static void Write(string text, string color) { if (string.IsNullOrEmpty(color)) { Write(text); return; } if (!ConsoleColor.TryParse(color, true, out ConsoleColor col)) { Write(text); } else { Write(text, col); } }
static void AgregarTempera(Paleta oPaleta) { ConsoleColor color; string marca; int cantidad; Console.WriteLine("Ingrese color: "); ConsoleColor.TryParse(Console.ReadLine(), out color); Console.WriteLine("Ingrese marca: "); marca = Console.ReadLine(); Console.WriteLine("Ingrese cantidad: "); int.TryParse(Console.ReadLine(), out cantidad); Tempera tempera6 = new Tempera(color, marca, cantidad); oPaleta.Colores.Add(tempera6); }