将控制台颜色转换为颜色? [英] Convert Consolecolor to Color?
本文介绍了将控制台颜色转换为颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将 ConsoleColor
转换为颜色
类型?
我需要这个创建这个方法的重载,它应该返回一个颜色,而不是一个Consolecolor:
I need this for create an overload of this method, which should return a color instead a Consolecolor:
''' <summary>
''' Generates a random ConsoleColor color.
''' </summary>
''' <returns>ConsoleColor.</returns>
Public Shared Function [ConsoleColor]() As ConsoleColor
Dim Rand As New Random
Return [Enum].Parse(GetType(ConsoleColor),
Rand.Next(0, 15))
End Function
ve try,但有时返回的颜色为空,因为ConsoleColor名称未知:
This is what I've tried, but sometimes the returned color is empty because the ConsoleColor name is unknown:
''' <summary>
''' Generates a random QB color.
''' </summary>
''' <returns>Color.</returns>
Public Shared Function QB() As Color
Dim Rand As New Random
Return Color.FromName([Enum].Parse(GetType(ConsoleColor),
Rand.Next(0, 15)).ToString)
End Function
PS:我想避免使用旧的VB6方法(QBColor函数)。
PS: I want to avoid the usage of old VB6 methods (QBColor function).
推荐答案
我今天遇到了这个问题,不能同意当前的答案。
I've had this problem myself today and cannot agree with both current answers.
我最后检查所有值,发现值非常不同,我不知道为什么人们推荐转换'按名称'。
I ended up checking all values and found that the values are very different, I have no idea why people recommend converting 'by name'.
Name Actual Drawing.Color of same name
Black #000000 #000000
DarkBlue #000080 #00008B
DarkGreen #008000 #006400
DarkCyan #008080 #008B8B
DarkRed #800000 #8B0000
DarkMagenta #800080 #8B008B
DarkYellow #808000 #000000
Gray #C0C0C0 #808080
DarkGray #808080 #A9A9A9
Blue #0000FF #0000FF
Green #00FF00 #008000
Cyan #00FFFF #00FFFF
Red #FF0000 #FF0000
Magenta #FF00FF #FF00FF
Yellow #FFFF00 #FFFF00
White #FFFFFF #FFFFFF
这篇关于将控制台颜色转换为颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文