本文整理汇总了C#中ConsoleColor.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# ConsoleColor.ToString方法的具体用法?C# ConsoleColor.ToString怎么用?C# ConsoleColor.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConsoleColor
的用法示例。
在下文中一共展示了ConsoleColor.ToString方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessHtmlColor
public static string ProcessHtmlColor(ConsoleColor color)
{
switch (color)
{
case (ConsoleColor.DarkBlue):
return "#012456";
case (ConsoleColor.Green):
return "Lime";
default:
return color.ToString();
}
}
示例2: ProcessTerminalColor
public static Color ProcessTerminalColor(ConsoleColor color)
{
switch (color)
{
case (ConsoleColor.DarkBlue):
return Color.FromArgb(1, 0x24, 0x56);
case (ConsoleColor.Green):
return Color.LimeGreen;
default:
return Color.FromName(color.ToString());
}
}
示例3: Run
public int Run()
{
normalForeColor = Console.ForegroundColor;
normalBackColor = Console.BackgroundColor;
highlightForeColor = ConsoleColor.Cyan;
highlightBackColor = Console.BackgroundColor;
errorForeColor = ConsoleColor.Red;
errorBackColor = Console.BackgroundColor;
if (args.Length == 0 || (args.Length > 0 && args[0].EqualsOneOf(StringComparison.InvariantCultureIgnoreCase, "/?", "/h", "/help"))) {
DisplayUsage(args.Length > 1 ? args[1] : null);
return 0;
}
if (args[0].EqualsOneOf(StringComparison.InvariantCultureIgnoreCase, "/hidden")) {
DisplayUsage(null, true);
return 0;
}
string cmdline;
StringBuilder cmdlineBuilder;
int result;
// TODO change this project to use the Config settings.
bool translateCR = false;
bool translateLF = false;
bool translateTab = false;
bool wrapOutput = false;
cmdlineBuilder = new StringBuilder();
try {
if (args.Length == 2 && (args[0].Equals("-s", StringComparison.CurrentCultureIgnoreCase) || args[0].Equals("-set", StringComparison.CurrentCultureIgnoreCase))) {
ConsoleColor tmpColor;
string arg;
arg = args[1];
if (arg.StartsWith("{") && arg.EndsWith("}")) {
arg = arg.Substring(1, arg.Length - 2);
}
// Convert old DOS colors to .net ConsoleColor
arg = ConvertDOSColors(arg); // TODO support bg
if (int.TryParse(arg, out result)
&& result >= (int)ConsoleColor.Black && result <= (int)ConsoleColor.White) {
tmpColor = (ConsoleColor)result;
} else if (ConsoleColorNames.Contains(arg, StringComparison.InvariantCultureIgnoreCase)) {
tmpColor = (ConsoleColor)Enum.Parse(typeof(ConsoleColor), arg, true);
} else {
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("error in -s argument: invalid color specified");
Console.ForegroundColor = normalForeColor;
return 10;
}
try {
Console.ForegroundColor = tmpColor;
} catch (Exception) {
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("error in -s argument: invalid color specified");
Console.ForegroundColor = normalForeColor;
return 10;
}
return 0;
}
if (ConsoleEx.IsInputRedirected) {
// When piping text to pcolor, I'm assuming that there is only
// one argument for pcolor and that is a color.
cmdlineBuilder.Append(args[0]);
cmdlineBuilder.Append(Console.In.ReadToEnd());
} else {
// Read all the content from the arguments.
for (int argsi = 0; argsi < args.Length; argsi++) {
string a = args[argsi];
string al = a.ToLowerInvariant();
if (al.Equals("-f") || al.Equals("-file")) {
if (argsi <= args.Length - 2) {
StringBuilder contents;
argsi++;
contents = new StringBuilder();
if (!File.Exists(args[argsi])) {
Console.ForegroundColor = errorForeColor;
WriteLine(ConsoleColor.Red, "-f the file was not found");
DisplayUsage("-f");
Console.ForegroundColor = normalForeColor;
return 4;
}
if (contents.LoadFromFile(args[argsi])) {
cmdlineBuilder.Append(contents.ToString());
}
} else {
Console.ForegroundColor = errorForeColor;
WriteLine(ConsoleColor.Red, "-f is missing its file name");
//.........这里部分代码省略.........
示例4: ConsoleColorToColor
private static Color ConsoleColorToColor(ConsoleColor console)
{
return Color.FromName(console.ToString());
}
示例5: SetConsoleColor
/// <summary>
/// Sets the console color to use for the specified event type.
/// </summary>
/// <param name="eventType">The TraceEventType to set the color for.</param>
/// <param name="color">The ConsoleColor to use for outputing trace messages of the specified type.</param>
/// <remarks>
/// <para>
/// When selecting colors note that PowerShell redefines DarkYellow and DarkMagenta and uses them
/// as default colors, so best to to avoid those two colors because result is not consistent.
/// </para>
/// </remarks>
public void SetConsoleColor(TraceEventType eventType, ConsoleColor color)
{
lock (_consoleLock)
{
if (!Enum.IsDefined(typeof (ConsoleColor), color))
{
throw new ArgumentOutOfRangeException("color", Resource.InvalidConsoleColor);
}
var key = eventType.ToString() + "Color";
Attributes[key] = color.ToString();
}
}
示例6: GetColor
private string GetColor(ConsoleColor consoleColor)
{
string color = string.Empty;
switch (consoleColor)
{
case ConsoleColor.DarkCyan:
color = consoleColor.ToString();
break;
default:
throw new NotImplementedException();
}
return color;
}
示例7: GetColorWithNoCases
private string GetColorWithNoCases(ConsoleColor consoleColor)
{
string color = string.Empty;
switch (consoleColor)
{
default:
color = consoleColor.ToString();
break;
}
return color;
}
示例8: consoleColorToBrush
static Brush consoleColorToBrush(ConsoleColor consoleColor)
{
// Recognize default system color.
if (consoleColor == Config.DefaultConsoleColor)
return Config.SystemFontBrush;
// Handle 'DarkYellow' which does not have a brush with a matching
// name.
if (consoleColor == ConsoleColor.DarkYellow)
return Brushes.DarkGoldenrod;
var colorStr = consoleColor.ToString();
return new BrushConverter().ConvertFromString(colorStr) as Brush;
}
示例9: ToString
public static string ToString(ConsoleColor color)
{
return color.ToString();
}
示例10: GetColorMapping
/// <summary>
/// Get color mapping xml element without background color
/// </summary>
/// <returns>
/// The color mapping.
/// </returns>
/// <param name="doc">
/// Document.
/// </param>
/// <param name="level">
/// Level.
/// </param>
/// <param name="foregroundColor">
/// Foreground color.
/// </param>
private XmlElement GetColorMapping(XmlDocument doc, string level, ConsoleColor foregroundColor)
{
return this.GetColorMapping(doc, level, foregroundColor.ToString(), String.Empty);
}
示例11: CrayonColor
public CrayonColor(ConsoleColor color) {
this.OriginalName = color.ToString();
this._consoleColor = color;
}
示例12: ConvertColor
private TerminalColor ConvertColor(ConsoleColor color, TerminalColor defaultColor)
{
TerminalColor result;
if(Enum.TryParse<TerminalColor>(color.ToString(), out result))
return result;
else
return defaultColor;
}