none
列舉 System.Drawing.Color RRS feed

  • 問題

  • 很久之前忘了在哪問過一樣的問題,也忘了最後是有人解答還是自己上網找到了解答

    當時馬上測試後的確可以達到我想要的效果

    但今天要找的時候找了很久都找不到...

    我的問題是這樣

    在System.Drawing.Color這個型別是一個結構

    當我宣告一個變數為System.Drawing.Color型別

    並且準備指派值給這個變數時

    Interllisence會像列舉型別那樣列舉出System.Drawing.Color裡頭的靜態屬性

    請問這樣的效果是怎麼做出來的???

    印象中要像要定義TypeConverter還是Attribute的樣子




    • 已編輯 MAGYC 2013年9月4日 上午 06:52
    2013年9月4日 上午 06:49

解答

  • 代码如下:

    Imports System
    Imports System.ComponentModel
    Imports System.Diagnostics
    Imports System.Drawing.Design
    Imports System.Globalization
    Imports System.Reflection
    Imports System.Text
    
    Namespace System.Drawing
        <DebuggerDisplay("{NameAndARGBValue}")>
        <Editor("System.Drawing.Design.ColorEditor, System.Drawing.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", GetType(UITypeEditor))>
        <Serializable>
        <TypeConverter(GetType(ColorConverter))>
        Public Structure Color
            Private Const ARGBAlphaShift As Integer = 24
    
            Private Const ARGBRedShift As Integer = 16
    
            Private Const ARGBGreenShift As Integer = 8
    
            Private Const ARGBBlueShift As Integer = 0
    
            Public ReadOnly Shared Empty As Color
    
            Private Shared StateKnownColorValid As Short
    
            Private Shared StateARGBValueValid As Short
    
            Private Shared StateValueMask As Short
    
            Private Shared StateNameValid As Short
    
            Private Shared NotDefinedValue As Long
    
            Private ReadOnly name As String
    
            Private ReadOnly value As Long
    
            Private ReadOnly knownColor As Short
    
            Private ReadOnly state As Short
    
            Public ReadOnly Property A As Byte
                Get
                    Return CByte((Me.Value >> 24 And CLng(255)))
                End Get
            End Property
    
            Public ReadOnly Shared Property AliceBlue As Color
                Get
                    Return New Color(KnownColor.AliceBlue)
                End Get
            End Property
    
            Public ReadOnly Shared Property AntiqueWhite As Color
                Get
                    Return New Color(KnownColor.AntiqueWhite)
                End Get
            End Property
    
            Public ReadOnly Shared Property Aqua As Color
                Get
                    Return New Color(KnownColor.Aqua)
                End Get
            End Property
    
            Public ReadOnly Shared Property Aquamarine As Color
                Get
                    Return New Color(KnownColor.Aquamarine)
                End Get
            End Property
    
            Public ReadOnly Shared Property Azure As Color
                Get
                    Return New Color(KnownColor.Azure)
                End Get
            End Property
    
            Public ReadOnly Property B As Byte
                Get
                    Return CByte((Me.Value And CLng(255)))
                End Get
            End Property
    
            Public ReadOnly Shared Property Beige As Color
                Get
                    Return New Color(KnownColor.Beige)
                End Get
            End Property
    
            Public ReadOnly Shared Property Bisque As Color
                Get
                    Return New Color(KnownColor.Bisque)
                End Get
            End Property
    
            Public ReadOnly Shared Property Black As Color
                Get
                    Return New Color(KnownColor.Black)
                End Get
            End Property
    
            Public ReadOnly Shared Property BlanchedAlmond As Color
                Get
                    Return New Color(KnownColor.BlanchedAlmond)
                End Get
            End Property
    
            Public ReadOnly Shared Property Blue As Color
                Get
                    Return New Color(KnownColor.Blue)
                End Get
            End Property
    
            Public ReadOnly Shared Property BlueViolet As Color
                Get
                    Return New Color(KnownColor.BlueViolet)
                End Get
            End Property
    
            Public ReadOnly Shared Property Brown As Color
                Get
                    Return New Color(KnownColor.Brown)
                End Get
            End Property
    
            Public ReadOnly Shared Property BurlyWood As Color
                Get
                    Return New Color(KnownColor.BurlyWood)
                End Get
            End Property
    
            Public ReadOnly Shared Property CadetBlue As Color
                Get
                    Return New Color(KnownColor.CadetBlue)
                End Get
            End Property
    
            Public ReadOnly Shared Property Chartreuse As Color
                Get
                    Return New Color(KnownColor.Chartreuse)
                End Get
            End Property
    
            Public ReadOnly Shared Property Chocolate As Color
                Get
                    Return New Color(KnownColor.Chocolate)
                End Get
            End Property
    
            Public ReadOnly Shared Property Coral As Color
                Get
                    Return New Color(KnownColor.Coral)
                End Get
            End Property
    
            Public ReadOnly Shared Property CornflowerBlue As Color
                Get
                    Return New Color(KnownColor.CornflowerBlue)
                End Get
            End Property
    
            Public ReadOnly Shared Property Cornsilk As Color
                Get
                    Return New Color(KnownColor.Cornsilk)
                End Get
            End Property
    
            Public ReadOnly Shared Property Crimson As Color
                Get
                    Return New Color(KnownColor.Crimson)
                End Get
            End Property
    
            Public ReadOnly Shared Property Cyan As Color
                Get
                    Return New Color(KnownColor.Cyan)
                End Get
            End Property
    
            Public ReadOnly Shared Property DarkBlue As Color
                Get
                    Return New Color(KnownColor.DarkBlue)
                End Get
            End Property
    
            Public ReadOnly Shared Property DarkCyan As Color
                Get
                    Return New Color(KnownColor.DarkCyan)
                End Get
            End Property
    
            Public ReadOnly Shared Property DarkGoldenrod As Color
                Get
                    Return New Color(KnownColor.DarkGoldenrod)
                End Get
            End Property
    
            Public ReadOnly Shared Property DarkGray As Color
                Get
                    Return New Color(KnownColor.DarkGray)
                End Get
            End Property
    
            Public ReadOnly Shared Property DarkGreen As Color
                Get
                    Return New Color(KnownColor.DarkGreen)
                End Get
            End Property
    
            Public ReadOnly Shared Property DarkKhaki As Color
                Get
                    Return New Color(KnownColor.DarkKhaki)
                End Get
            End Property
    
            Public ReadOnly Shared Property DarkMagenta As Color
                Get
                    Return New Color(KnownColor.DarkMagenta)
                End Get
            End Property
    
            Public ReadOnly Shared Property DarkOliveGreen As Color
                Get
                    Return New Color(KnownColor.DarkOliveGreen)
                End Get
            End Property
    
            Public ReadOnly Shared Property DarkOrange As Color
                Get
                    Return New Color(KnownColor.DarkOrange)
                End Get
            End Property
    
            Public ReadOnly Shared Property DarkOrchid As Color
                Get
                    Return New Color(KnownColor.DarkOrchid)
                End Get
            End Property
    
            Public ReadOnly Shared Property DarkRed As Color
                Get
                    Return New Color(KnownColor.DarkRed)
                End Get
            End Property
    
            Public ReadOnly Shared Property DarkSalmon As Color
                Get
                    Return New Color(KnownColor.DarkSalmon)
                End Get
            End Property
    
            Public ReadOnly Shared Property DarkSeaGreen As Color
                Get
                    Return New Color(KnownColor.DarkSeaGreen)
                End Get
            End Property
    
            Public ReadOnly Shared Property DarkSlateBlue As Color
                Get
                    Return New Color(KnownColor.DarkSlateBlue)
                End Get
            End Property
    
            Public ReadOnly Shared Property DarkSlateGray As Color
                Get
                    Return New Color(KnownColor.DarkSlateGray)
                End Get
            End Property
    
            Public ReadOnly Shared Property DarkTurquoise As Color
                Get
                    Return New Color(KnownColor.DarkTurquoise)
                End Get
            End Property
    
            Public ReadOnly Shared Property DarkViolet As Color
                Get
                    Return New Color(KnownColor.DarkViolet)
                End Get
            End Property
    
            Public ReadOnly Shared Property DeepPink As Color
                Get
                    Return New Color(KnownColor.DeepPink)
                End Get
            End Property
    
            Public ReadOnly Shared Property DeepSkyBlue As Color
                Get
                    Return New Color(KnownColor.DeepSkyBlue)
                End Get
            End Property
    
            Public ReadOnly Shared Property DimGray As Color
                Get
                    Return New Color(KnownColor.DimGray)
                End Get
            End Property
    
            Public ReadOnly Shared Property DodgerBlue As Color
                Get
                    Return New Color(KnownColor.DodgerBlue)
                End Get
            End Property
    
            Public ReadOnly Shared Property Firebrick As Color
                Get
                    Return New Color(KnownColor.Firebrick)
                End Get
            End Property
    
            Public ReadOnly Shared Property FloralWhite As Color
                Get
                    Return New Color(KnownColor.FloralWhite)
                End Get
            End Property
    
            Public ReadOnly Shared Property ForestGreen As Color
                Get
                    Return New Color(KnownColor.ForestGreen)
                End Get
            End Property
    
            Public ReadOnly Shared Property Fuchsia As Color
                Get
                    Return New Color(KnownColor.Fuchsia)
                End Get
            End Property
    
            Public ReadOnly Property G As Byte
                Get
                    Return CByte((Me.Value >> 8 And CLng(255)))
                End Get
            End Property
    
            Public ReadOnly Shared Property Gainsboro As Color
                Get
                    Return New Color(KnownColor.Gainsboro)
                End Get
            End Property
    
            Public ReadOnly Shared Property GhostWhite As Color
                Get
                    Return New Color(KnownColor.GhostWhite)
                End Get
            End Property
    
            Public ReadOnly Shared Property Gold As Color
                Get
                    Return New Color(KnownColor.Gold)
                End Get
            End Property
    
            Public ReadOnly Shared Property Goldenrod As Color
                Get
                    Return New Color(KnownColor.Goldenrod)
                End Get
            End Property
    
            Public ReadOnly Shared Property Gray As Color
                Get
                    Return New Color(KnownColor.Gray)
                End Get
            End Property
    
            Public ReadOnly Shared Property Green As Color
                Get
                    Return New Color(KnownColor.Green)
                End Get
            End Property
    
            Public ReadOnly Shared Property GreenYellow As Color
                Get
                    Return New Color(KnownColor.GreenYellow)
                End Get
            End Property
    
            Public ReadOnly Shared Property Honeydew As Color
                Get
                    Return New Color(KnownColor.Honeydew)
                End Get
            End Property
    
            Public ReadOnly Shared Property HotPink As Color
                Get
                    Return New Color(KnownColor.HotPink)
                End Get
            End Property
    
            Public ReadOnly Shared Property IndianRed As Color
                Get
                    Return New Color(KnownColor.IndianRed)
                End Get
            End Property
    
            Public ReadOnly Shared Property Indigo As Color
                Get
                    Return New Color(KnownColor.Indigo)
                End Get
            End Property
    
            Public ReadOnly Property IsEmpty As Boolean
                Get
                    Return Me.state = 0
                End Get
            End Property
    
            Public ReadOnly Property IsKnownColor As Boolean
                Get
                    Return (Me.state And Color.StateKnownColorValid) <> 0
                End Get
            End Property
    
            Public ReadOnly Property IsNamedColor As Boolean
                Get
                    If ((Me.state And Color.StateNameValid) <> 0) Then
                        Return True
                    End If
                    Return Me.IsKnownColor
                End Get
            End Property
    
            Public ReadOnly Property IsSystemColor As Boolean
                Get
                    If (Not Me.IsKnownColor) Then
                        Return False
                    End If
                    If (Me.knownColor <= 26) Then
                        Return True
                    End If
                    Return Me.knownColor > 167
                End Get
            End Property
    
            Public ReadOnly Shared Property Ivory As Color
                Get
                    Return New Color(KnownColor.Ivory)
                End Get
            End Property
    
            Public ReadOnly Shared Property Khaki As Color
                Get
                    Return New Color(KnownColor.Khaki)
                End Get
            End Property
    
            Public ReadOnly Shared Property Lavender As Color
                Get
                    Return New Color(KnownColor.Lavender)
                End Get
            End Property
    
            Public ReadOnly Shared Property LavenderBlush As Color
                Get
                    Return New Color(KnownColor.LavenderBlush)
                End Get
            End Property
    
            Public ReadOnly Shared Property LawnGreen As Color
                Get
                    Return New Color(KnownColor.LawnGreen)
                End Get
            End Property
    
            Public ReadOnly Shared Property LemonChiffon As Color
                Get
                    Return New Color(KnownColor.LemonChiffon)
                End Get
            End Property
    
            Public ReadOnly Shared Property LightBlue As Color
                Get
                    Return New Color(KnownColor.LightBlue)
                End Get
            End Property
    
            Public ReadOnly Shared Property LightCoral As Color
                Get
                    Return New Color(KnownColor.LightCoral)
                End Get
            End Property
    
            Public ReadOnly Shared Property LightCyan As Color
                Get
                    Return New Color(KnownColor.LightCyan)
                End Get
            End Property
    
            Public ReadOnly Shared Property LightGoldenrodYellow As Color
                Get
                    Return New Color(KnownColor.LightGoldenrodYellow)
                End Get
            End Property
    
            Public ReadOnly Shared Property LightGray As Color
                Get
                    Return New Color(KnownColor.LightGray)
                End Get
            End Property
    
            Public ReadOnly Shared Property LightGreen As Color
                Get
                    Return New Color(KnownColor.LightGreen)
                End Get
            End Property
    
            Public ReadOnly Shared Property LightPink As Color
                Get
                    Return New Color(KnownColor.LightPink)
                End Get
            End Property
    
            Public ReadOnly Shared Property LightSalmon As Color
                Get
                    Return New Color(KnownColor.LightSalmon)
                End Get
            End Property
    
            Public ReadOnly Shared Property LightSeaGreen As Color
                Get
                    Return New Color(KnownColor.LightSeaGreen)
                End Get
            End Property
    
            Public ReadOnly Shared Property LightSkyBlue As Color
                Get
                    Return New Color(KnownColor.LightSkyBlue)
                End Get
            End Property
    
            Public ReadOnly Shared Property LightSlateGray As Color
                Get
                    Return New Color(KnownColor.LightSlateGray)
                End Get
            End Property
    
            Public ReadOnly Shared Property LightSteelBlue As Color
                Get
                    Return New Color(KnownColor.LightSteelBlue)
                End Get
            End Property
    
            Public ReadOnly Shared Property LightYellow As Color
                Get
                    Return New Color(KnownColor.LightYellow)
                End Get
            End Property
    
            Public ReadOnly Shared Property Lime As Color
                Get
                    Return New Color(KnownColor.Lime)
                End Get
            End Property
    
            Public ReadOnly Shared Property LimeGreen As Color
                Get
                    Return New Color(KnownColor.LimeGreen)
                End Get
            End Property
    
            Public ReadOnly Shared Property Linen As Color
                Get
                    Return New Color(KnownColor.Linen)
                End Get
            End Property
    
            Public ReadOnly Shared Property Magenta As Color
                Get
                    Return New Color(KnownColor.Magenta)
                End Get
            End Property
    
            Public ReadOnly Shared Property Maroon As Color
                Get
                    Return New Color(KnownColor.Maroon)
                End Get
            End Property
    
            Public ReadOnly Shared Property MediumAquamarine As Color
                Get
                    Return New Color(KnownColor.MediumAquamarine)
                End Get
            End Property
    
            Public ReadOnly Shared Property MediumBlue As Color
                Get
                    Return New Color(KnownColor.MediumBlue)
                End Get
            End Property
    
            Public ReadOnly Shared Property MediumOrchid As Color
                Get
                    Return New Color(KnownColor.MediumOrchid)
                End Get
            End Property
    
            Public ReadOnly Shared Property MediumPurple As Color
                Get
                    Return New Color(KnownColor.MediumPurple)
                End Get
            End Property
    
            Public ReadOnly Shared Property MediumSeaGreen As Color
                Get
                    Return New Color(KnownColor.MediumSeaGreen)
                End Get
            End Property
    
            Public ReadOnly Shared Property MediumSlateBlue As Color
                Get
                    Return New Color(KnownColor.MediumSlateBlue)
                End Get
            End Property
    
            Public ReadOnly Shared Property MediumSpringGreen As Color
                Get
                    Return New Color(KnownColor.MediumSpringGreen)
                End Get
            End Property
    
            Public ReadOnly Shared Property MediumTurquoise As Color
                Get
                    Return New Color(KnownColor.MediumTurquoise)
                End Get
            End Property
    
            Public ReadOnly Shared Property MediumVioletRed As Color
                Get
                    Return New Color(KnownColor.MediumVioletRed)
                End Get
            End Property
    
            Public ReadOnly Shared Property MidnightBlue As Color
                Get
                    Return New Color(KnownColor.MidnightBlue)
                End Get
            End Property
    
            Public ReadOnly Shared Property MintCream As Color
                Get
                    Return New Color(KnownColor.MintCream)
                End Get
            End Property
    
            Public ReadOnly Shared Property MistyRose As Color
                Get
                    Return New Color(KnownColor.MistyRose)
                End Get
            End Property
    
            Public ReadOnly Shared Property Moccasin As Color
                Get
                    Return New Color(KnownColor.Moccasin)
                End Get
            End Property
    
            Public ReadOnly Property Name As String
                Get
                    If ((Me.state And Color.StateNameValid) <> 0) Then
                        Return Me.name
                    End If
                    If (Not Me.IsKnownColor) Then
                        Return Convert.ToString(Me.value, 16)
                    End If
                    Dim name As String = KnownColorTable.KnownColorToName(DirectCast(Me.knownColor, KnownColor))
                    If (name IsNot Nothing) Then
                        Return name
                    End If
                    Return DirectCast(Me.knownColor, KnownColor).ToString()
                End Get
            End Property
    
            Private ReadOnly Property NameAndARGBValue As String
                Get
                    Dim currentCulture As CultureInfo = CultureInfo.CurrentCulture
                    Dim name() As Object = { Me.Name, Me.A, Me.R, Me.G, Me.B }
                    Return String.Format(currentCulture, "{{Name={0}, ARGB=({1}, {2}, {3}, {4})}}", name)
                End Get
            End Property
    
            Public ReadOnly Shared Property NavajoWhite As Color
                Get
                    Return New Color(KnownColor.NavajoWhite)
                End Get
            End Property
    
            Public ReadOnly Shared Property Navy As Color
                Get
                    Return New Color(KnownColor.Navy)
                End Get
            End Property
    
            Public ReadOnly Shared Property OldLace As Color
                Get
                    Return New Color(KnownColor.OldLace)
                End Get
            End Property
    
            Public ReadOnly Shared Property Olive As Color
                Get
                    Return New Color(KnownColor.Olive)
                End Get
            End Property
    
            Public ReadOnly Shared Property OliveDrab As Color
                Get
                    Return New Color(KnownColor.OliveDrab)
                End Get
            End Property
    
            Public ReadOnly Shared Property Orange As Color
                Get
                    Return New Color(KnownColor.Orange)
                End Get
            End Property
    
            Public ReadOnly Shared Property OrangeRed As Color
                Get
                    Return New Color(KnownColor.OrangeRed)
                End Get
            End Property
    
            Public ReadOnly Shared Property Orchid As Color
                Get
                    Return New Color(KnownColor.Orchid)
                End Get
            End Property
    
            Public ReadOnly Shared Property PaleGoldenrod As Color
                Get
                    Return New Color(KnownColor.PaleGoldenrod)
                End Get
            End Property
    
            Public ReadOnly Shared Property PaleGreen As Color
                Get
                    Return New Color(KnownColor.PaleGreen)
                End Get
            End Property
    
            Public ReadOnly Shared Property PaleTurquoise As Color
                Get
                    Return New Color(KnownColor.PaleTurquoise)
                End Get
            End Property
    
            Public ReadOnly Shared Property PaleVioletRed As Color
                Get
                    Return New Color(KnownColor.PaleVioletRed)
                End Get
            End Property
    
            Public ReadOnly Shared Property PapayaWhip As Color
                Get
                    Return New Color(KnownColor.PapayaWhip)
                End Get
            End Property
    
            Public ReadOnly Shared Property PeachPuff As Color
                Get
                    Return New Color(KnownColor.PeachPuff)
                End Get
            End Property
    
            Public ReadOnly Shared Property Peru As Color
                Get
                    Return New Color(KnownColor.Peru)
                End Get
            End Property
    
            Public ReadOnly Shared Property Pink As Color
                Get
                    Return New Color(KnownColor.Pink)
                End Get
            End Property
    
            Public ReadOnly Shared Property Plum As Color
                Get
                    Return New Color(KnownColor.Plum)
                End Get
            End Property
    
            Public ReadOnly Shared Property PowderBlue As Color
                Get
                    Return New Color(KnownColor.PowderBlue)
                End Get
            End Property
    
            Public ReadOnly Shared Property Purple As Color
                Get
                    Return New Color(KnownColor.Purple)
                End Get
            End Property
    
            Public ReadOnly Property R As Byte
                Get
                    Return CByte((Me.Value >> 16 And CLng(255)))
                End Get
            End Property
    
            Public ReadOnly Shared Property Red As Color
                Get
                    Return New Color(KnownColor.Red)
                End Get
            End Property
    
            Public ReadOnly Shared Property RosyBrown As Color
                Get
                    Return New Color(KnownColor.RosyBrown)
                End Get
            End Property
    
            Public ReadOnly Shared Property RoyalBlue As Color
                Get
                    Return New Color(KnownColor.RoyalBlue)
                End Get
            End Property
    
            Public ReadOnly Shared Property SaddleBrown As Color
                Get
                    Return New Color(KnownColor.SaddleBrown)
                End Get
            End Property
    
            Public ReadOnly Shared Property Salmon As Color
                Get
                    Return New Color(KnownColor.Salmon)
                End Get
            End Property
    
            Public ReadOnly Shared Property SandyBrown As Color
                Get
                    Return New Color(KnownColor.SandyBrown)
                End Get
            End Property
    
            Public ReadOnly Shared Property SeaGreen As Color
                Get
                    Return New Color(KnownColor.SeaGreen)
                End Get
            End Property
    
            Public ReadOnly Shared Property SeaShell As Color
                Get
                    Return New Color(KnownColor.SeaShell)
                End Get
            End Property
    
            Public ReadOnly Shared Property Sienna As Color
                Get
                    Return New Color(KnownColor.Sienna)
                End Get
            End Property
    
            Public ReadOnly Shared Property Silver As Color
                Get
                    Return New Color(KnownColor.Silver)
                End Get
            End Property
    
            Public ReadOnly Shared Property SkyBlue As Color
                Get
                    Return New Color(KnownColor.SkyBlue)
                End Get
            End Property
    
            Public ReadOnly Shared Property SlateBlue As Color
                Get
                    Return New Color(KnownColor.SlateBlue)
                End Get
            End Property
    
            Public ReadOnly Shared Property SlateGray As Color
                Get
                    Return New Color(KnownColor.SlateGray)
                End Get
            End Property
    
            Public ReadOnly Shared Property Snow As Color
                Get
                    Return New Color(KnownColor.Snow)
                End Get
            End Property
    
            Public ReadOnly Shared Property SpringGreen As Color
                Get
                    Return New Color(KnownColor.SpringGreen)
                End Get
            End Property
    
            Public ReadOnly Shared Property SteelBlue As Color
                Get
                    Return New Color(KnownColor.SteelBlue)
                End Get
            End Property
    
            Public ReadOnly Shared Property Tan As Color
                Get
                    Return New Color(KnownColor.Tan)
                End Get
            End Property
    
            Public ReadOnly Shared Property Teal As Color
                Get
                    Return New Color(KnownColor.Teal)
                End Get
            End Property
    
            Public ReadOnly Shared Property Thistle As Color
                Get
                    Return New Color(KnownColor.Thistle)
                End Get
            End Property
    
            Public ReadOnly Shared Property Tomato As Color
                Get
                    Return New Color(KnownColor.Tomato)
                End Get
            End Property
    
            Public ReadOnly Shared Property Transparent As Color
                Get
                    Return New Color(KnownColor.Transparent)
                End Get
            End Property
    
            Public ReadOnly Shared Property Turquoise As Color
                Get
                    Return New Color(KnownColor.Turquoise)
                End Get
            End Property
    
            Private ReadOnly Property Value As Long
                Get
                    If ((Me.state And Color.StateValueMask) <> 0) Then
                        Return Me.value
                    End If
                    If (Not Me.IsKnownColor) Then
                        Return Color.NotDefinedValue
                    End If
                    Return CLng(KnownColorTable.KnownColorToArgb(DirectCast(Me.knownColor, KnownColor)))
                End Get
            End Property
    
            Public ReadOnly Shared Property Violet As Color
                Get
                    Return New Color(KnownColor.Violet)
                End Get
            End Property
    
            Public ReadOnly Shared Property Wheat As Color
                Get
                    Return New Color(KnownColor.Wheat)
                End Get
            End Property
    
            Public ReadOnly Shared Property White As Color
                Get
                    Return New Color(KnownColor.White)
                End Get
            End Property
    
            Public ReadOnly Shared Property WhiteSmoke As Color
                Get
                    Return New Color(KnownColor.WhiteSmoke)
                End Get
            End Property
    
            Public ReadOnly Shared Property Yellow As Color
                Get
                    Return New Color(KnownColor.Yellow)
                End Get
            End Property
    
            Public ReadOnly Shared Property YellowGreen As Color
                Get
                    Return New Color(KnownColor.YellowGreen)
                End Get
            End Property
    
            Shared Sub New()
                Color.Empty = New Color()
                Color.StateKnownColorValid = 1
                Color.StateARGBValueValid = 2
                Color.StateValueMask = Color.StateARGBValueValid
                Color.StateNameValid = 8
                Color.NotDefinedValue = CLng(0)
            End Sub
    
            Friend Sub New(ByVal knownColor As System.Drawing.KnownColor)
                Me.value = CLng(0)
                Me.state = Color.StateKnownColorValid
                Me.name = Nothing
                Me.knownColor = CShort(knownColor)
            End Sub
    
            Private Sub New(ByVal value As Long, ByVal state As Short, ByVal name As String, ByVal knownColor As System.Drawing.KnownColor)
                Me.value = value
                Me.state = state
                Me.name = name
                Me.knownColor = CShort(knownColor)
            End Sub
    
            Private Shared Sub CheckByte(ByVal value As Integer, ByVal name As String)
                If (value < 0 OrElse value > 255) Then
                    Dim objArray() As Object = { name, value, 0, 255 }
                    Throw New ArgumentException(SR.GetString("InvalidEx2BoundArgument", objArray))
                End If
            End Sub
    
            Public Overrides Function Equals(ByVal obj As Object) As Boolean
                If (TypeOf obj Is System.Drawing.Color) Then
                    Dim color As System.Drawing.Color = DirectCast(obj, System.Drawing.Color)
                    If (Me.value = color.value AndAlso Me.state = color.state AndAlso Me.knownColor = color.knownColor) Then
                        If (Me.name = color.name) Then
                            Return True
                        End If
                        If (Me.name Is Nothing OrElse color.name Is Nothing) Then
                            Return False
                        End If
                        Return Me.name.Equals(Me.name)
                    End If
                End If
                Return False
            End Function
    
            Public Shared Function FromArgb(ByVal argb As Integer) As Color
                Return New Color(CLng((CLng(argb) And DirectCast(-1, ULong))), Color.StateARGBValueValid, Nothing, 0)
            End Function
    
            Public Shared Function FromArgb(ByVal alpha As Integer, ByVal red As Integer, ByVal green As Integer, ByVal blue As Integer) As Color
                Color.CheckByte(alpha, "alpha")
                Color.CheckByte(red, "red")
                Color.CheckByte(green, "green")
                Color.CheckByte(blue, "blue")
                Return New Color(Color.MakeArgb(CByte(alpha), CByte(red), CByte(green), CByte(blue)), Color.StateARGBValueValid, Nothing, 0)
            End Function
    
            Public Shared Function FromArgb(ByVal alpha As Integer, ByVal baseColor As Color) As Color
                Color.CheckByte(alpha, "alpha")
                Return New Color(Color.MakeArgb(CByte(alpha), baseColor.R, baseColor.G, baseColor.B), Color.StateARGBValueValid, Nothing, 0)
            End Function
    
            Public Shared Function FromArgb(ByVal red As Integer, ByVal green As Integer, ByVal blue As Integer) As Color
                Return Color.FromArgb(255, red, green, blue)
            End Function
    
            Public Shared Function FromKnownColor(ByVal color As KnownColor) As System.Drawing.Color
                If (ClientUtils.IsEnumValid(color, CInt(color), 1, 174)) Then
                    Return New System.Drawing.Color(color)
                End If
                Return System.Drawing.Color.FromName(color.ToString())
            End Function
    
            Public Shared Function FromName(ByVal name As String) As Color
                Dim namedColor As Object = ColorConverter.GetNamedColor(name)
                If (namedColor IsNot Nothing) Then
                    Return DirectCast(namedColor, Color)
                End If
                Return New Color(Color.NotDefinedValue, Color.StateNameValid, name, 0)
            End Function
    
            Public Function GetBrightness() As Single
                Dim r As Single = CSng(Me.R) / 255!
                Dim g As Single = CSng(Me.G) / 255!
                Dim b As Single = CSng(Me.B) / 255!
                Dim [single] As Single = r
                Dim single1 As Single = r
                If (g > [single]) Then
                    [single] = g
                End If
                If (b > [single]) Then
                    [single] = b
                End If
                If (g < single1) Then
                    single1 = g
                End If
                If (b < single1) Then
                    single1 = b
                End If
                Return ([single] + single1) / 2!
            End Function
    
            Public Overrides Function GetHashCode() As Integer
                Return Me.value.GetHashCode() Xor Me.state.GetHashCode() Xor Me.knownColor.GetHashCode()
            End Function
    
            Public Function GetHue() As Single
                If (Me.R = Me.G AndAlso Me.G = Me.B) Then
                    Return 0!
                End If
                Dim r As Single = CSng(Me.R) / 255!
                Dim g As Single = CSng(Me.G) / 255!
                Dim b As Single = CSng(Me.B) / 255!
                Dim [single] As Single = 0!
                Dim single1 As Single = r
                Dim single2 As Single = r
                If (g > single1) Then
                    single1 = g
                End If
                If (b > single1) Then
                    single1 = b
                End If
                If (g < single2) Then
                    single2 = g
                End If
                If (b < single2) Then
                    single2 = b
                End If
                Dim single3 As Single = single1 - single2
                If (r = single1) Then
                    [single] = (g - b) / single3
                ElseIf (g = single1) Then
                    [single] = 2! + (b - r) / single3
                ElseIf (b = single1) Then
                    [single] = 4! + (r - g) / single3
                End If
                [single] = [single] * 60!
                If ([single] < 0!) Then
                    [single] = [single] + 360!
                End If
                Return [single]
            End Function
    
            Public Function GetSaturation() As Single
                Dim r As Single = CSng(Me.R) / 255!
                Dim g As Single = CSng(Me.G) / 255!
                Dim b As Single = CSng(Me.B) / 255!
                Dim [single] As Single = 0!
                Dim single1 As Single = r
                Dim single2 As Single = r
                If (g > single1) Then
                    single1 = g
                End If
                If (b > single1) Then
                    single1 = b
                End If
                If (g < single2) Then
                    single2 = g
                End If
                If (b < single2) Then
                    single2 = b
                End If
                If (single1 <> single2) Then
                    [single] = If(CDbl(((single1 + single2) / 2!)) > 0.5, (single1 - single2) / (2! - single1 - single2), (single1 - single2) / (single1 + single2))
                End If
                Return [single]
            End Function
    
            Private Shared Function MakeArgb(ByVal alpha As Byte, ByVal red As Byte, ByVal green As Byte, ByVal blue As Byte) As Long
                Return CLng((DirectCast((red << 16 Or green << 8 Or blue Or alpha << 24), ULong) And DirectCast(-1, ULong)))
            End Function
    
            Public Shared Operator =(ByVal left As Color, ByVal right As Color) As Boolean
                If (left.value <> right.value OrElse left.state <> right.state OrElse left.knownColor <> right.knownColor) Then
                    Return False
                End If
                If (left.name = right.name) Then
                    Return True
                End If
                If (left.name Is Nothing OrElse right.name Is Nothing) Then
                    Return False
                End If
                Return left.name.Equals(right.name)
            End Operator
    
            Public Shared Operator <>(ByVal left As Color, ByVal right As Color) As Boolean
                Return Not (left = right)
            End Operator
    
            Public Function ToArgb() As Integer
                Return CInt(Me.Value)
            End Function
    
            Public Function ToKnownColor() As KnownColor
                Return DirectCast(Me.knownColor, KnownColor)
            End Function
    
            Public Overrides Function ToString() As String
                Dim stringBuilder As System.Text.StringBuilder = New System.Text.StringBuilder(32)
                stringBuilder.Append(Me.[GetType]().Name)
                stringBuilder.Append(" [")
                If ((Me.state And Color.StateNameValid) <> 0) Then
                    stringBuilder.Append(Me.Name)
                ElseIf ((Me.state And Color.StateKnownColorValid) <> 0) Then
                    stringBuilder.Append(Me.Name)
                ElseIf ((Me.state And Color.StateValueMask) = 0) Then
                    stringBuilder.Append("Empty")
                Else
                    stringBuilder.Append("A=")
                    stringBuilder.Append(Me.A)
                    stringBuilder.Append(", R=")
                    stringBuilder.Append(Me.R)
                    stringBuilder.Append(", G=")
                    stringBuilder.Append(Me.G)
                    stringBuilder.Append(", B=")
                    stringBuilder.Append(Me.B)
                End If
                stringBuilder.Append("]")
                Return stringBuilder.ToString()
            End Function
        End Structure
    End Namespace
    ColorConverter代码:
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.ComponentModel.Design.Serialization;
    using System.Globalization;
    using System.Reflection;
    
    namespace System.Drawing
    {
        public class ColorConverter : TypeConverter
        {
            private static string ColorConstantsLock;
    
            private static Hashtable colorConstants;
    
            private static string SystemColorConstantsLock;
    
            private static Hashtable systemColorConstants;
    
            private static string ValuesLock;
    
            private static TypeConverter.StandardValuesCollection values;
    
            private static Hashtable Colors
            {
                get
                {
                    if (ColorConverter.colorConstants == null)
                    {
                        lock (ColorConverter.ColorConstantsLock)
                        {
                            if (ColorConverter.colorConstants == null)
                            {
                                Hashtable hashtables = new Hashtable(StringComparer.OrdinalIgnoreCase);
                                ColorConverter.FillConstants(hashtables, typeof(Color));
                                ColorConverter.colorConstants = hashtables;
                            }
                        }
                    }
                    return ColorConverter.colorConstants;
                }
            }
    
            private static Hashtable SystemColors
            {
                get
                {
                    if (ColorConverter.systemColorConstants == null)
                    {
                        lock (ColorConverter.SystemColorConstantsLock)
                        {
                            if (ColorConverter.systemColorConstants == null)
                            {
                                Hashtable hashtables = new Hashtable(StringComparer.OrdinalIgnoreCase);
                                ColorConverter.FillConstants(hashtables, typeof(SystemColors));
                                ColorConverter.systemColorConstants = hashtables;
                            }
                        }
                    }
                    return ColorConverter.systemColorConstants;
                }
            }
    
            static ColorConverter()
            {
                ColorConverter.ColorConstantsLock = "colorConstants";
                ColorConverter.SystemColorConstantsLock = "systemColorConstants";
                ColorConverter.ValuesLock = "values";
            }
    
            public ColorConverter()
            {
            }
    
            public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
            {
                if (sourceType == typeof(string))
                {
                    return true;
                }
                return base.CanConvertFrom(context, sourceType);
            }
    
            public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
            {
                if (destinationType == typeof(InstanceDescriptor))
                {
                    return true;
                }
                return base.CanConvertTo(context, destinationType);
            }
    
            public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
            {
                string str = value as string;
                if (str == null)
                {
                    return base.ConvertFrom(context, culture, value);
                }
                object namedColor = null;
                string str1 = str.Trim();
                if (str1.Length != 0)
                {
                    namedColor = ColorConverter.GetNamedColor(str1);
                    if (namedColor == null)
                    {
                        if (culture == null)
                        {
                            culture = CultureInfo.CurrentCulture;
                        }
                        char listSeparator = culture.TextInfo.ListSeparator[0];
                        bool flag = true;
                        TypeConverter converter = TypeDescriptor.GetConverter(typeof(int));
                        if (str1.IndexOf(listSeparator) == -1)
                        {
                            if (str1.Length >= 2 && (str1[0] == '\'' || str1[0] == '\"') && str1[0] == str1[str1.Length - 1])
                            {
                                string str2 = str1.Substring(1, str1.Length - 2);
                                namedColor = Color.FromName(str2);
                                flag = false;
                            }
                            else if (str1.Length == 7 && str1[0] == '#' || str1.Length == 8 && (str1.StartsWith("0x") || str1.StartsWith("0X")) || str1.Length == 8 && (str1.StartsWith("&h") || str1.StartsWith("&H")))
                            {
                                namedColor = Color.FromArgb(-16777216 | (int)converter.ConvertFromString(context, culture, str1));
                            }
                        }
                        if (namedColor == null)
                        {
                            string[] strArrays = str1.Split(new char[] { listSeparator });
                            int[] numArray = new int[(int)strArrays.Length];
                            for (int i = 0; i < (int)numArray.Length; i++)
                            {
                                numArray[i] = (int)converter.ConvertFromString(context, culture, strArrays[i]);
                            }
                            switch ((int)numArray.Length)
                            {
                                case 1:
                                {
                                    namedColor = Color.FromArgb(numArray[0]);
                                    goto case 2;
                                }
                                case 2:
                                {
                                    flag = true;
                                    break;
                                }
                                case 3:
                                {
                                    namedColor = Color.FromArgb(numArray[0], numArray[1], numArray[2]);
                                    goto case 2;
                                }
                                case 4:
                                {
                                    namedColor = Color.FromArgb(numArray[0], numArray[1], numArray[2], numArray[3]);
                                    goto case 2;
                                }
                                default:
                                {
                                    goto case 2;
                                }
                            }
                        }
                        if (namedColor != null && flag)
                        {
                            int argb = ((Color)namedColor).ToArgb();
                            foreach (Color color in ColorConverter.Colors.Values)
                            {
                                if (color.ToArgb() != argb)
                                {
                                    continue;
                                }
                                namedColor = color;
                                break;
                            }
                        }
                    }
                    if (namedColor == null)
                    {
                        object[] objArray = new object[] { str1 };
                        throw new ArgumentException(SR.GetString("InvalidColor", objArray));
                    }
                }
                else
                {
                    namedColor = Color.Empty;
                }
                return namedColor;
            }
    
            public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
            {
                string[] str;
                if (destinationType == null)
                {
                    throw new ArgumentNullException("destinationType");
                }
                if (value is Color)
                {
                    if (destinationType == typeof(string))
                    {
                        Color color = (Color)value;
                        if (color == Color.Empty)
                        {
                            return string.Empty;
                        }
                        if (color.IsKnownColor)
                        {
                            return color.Name;
                        }
                        if (color.IsNamedColor)
                        {
                            return string.Concat("'", color.Name, "'");
                        }
                        if (culture == null)
                        {
                            culture = CultureInfo.CurrentCulture;
                        }
                        string str1 = string.Concat(culture.TextInfo.ListSeparator, " ");
                        TypeConverter converter = TypeDescriptor.GetConverter(typeof(int));
                        int num = 0;
                        if (color.A >= 255)
                        {
                            str = new string[3];
                        }
                        else
                        {
                            str = new string[4];
                            int num1 = num;
                            num = num1 + 1;
                            str[num1] = converter.ConvertToString(context, culture, color.A);
                        }
                        int num2 = num;
                        num = num2 + 1;
                        str[num2] = converter.ConvertToString(context, culture, color.R);
                        int num3 = num;
                        num = num3 + 1;
                        str[num3] = converter.ConvertToString(context, culture, color.G);
                        int num4 = num;
                        num = num4 + 1;
                        str[num4] = converter.ConvertToString(context, culture, color.B);
                        return string.Join(str1, str);
                    }
                    if (destinationType == typeof(InstanceDescriptor))
                    {
                        MemberInfo field = null;
                        object[] name = null;
                        Color color1 = (Color)value;
                        if (color1.IsEmpty)
                        {
                            field = typeof(Color).GetField("Empty");
                        }
                        else if (color1.IsSystemColor)
                        {
                            field = typeof(SystemColors).GetProperty(color1.Name);
                        }
                        else if (color1.IsKnownColor)
                        {
                            field = typeof(Color).GetProperty(color1.Name);
                        }
                        else if (color1.A != 255)
                        {
                            Type type = typeof(Color);
                            Type[] typeArray = new Type[] { typeof(int), typeof(int), typeof(int), typeof(int) };
                            field = type.GetMethod("FromArgb", typeArray);
                            object[] a = new object[] { color1.A, color1.R, color1.G, color1.B };
                            name = a;
                        }
                        else if (!color1.IsNamedColor)
                        {
                            Type type1 = typeof(Color);
                            Type[] typeArray1 = new Type[] { typeof(int), typeof(int), typeof(int) };
                            field = type1.GetMethod("FromArgb", typeArray1);
                            object[] r = new object[] { color1.R, color1.G, color1.B };
                            name = r;
                        }
                        else
                        {
                            Type type2 = typeof(Color);
                            Type[] typeArray2 = new Type[] { typeof(string) };
                            field = type2.GetMethod("FromName", typeArray2);
                            name = new object[] { color1.Name };
                        }
                        if (field == null)
                        {
                            return null;
                        }
                        return new InstanceDescriptor(field, name);
                    }
                }
                return base.ConvertTo(context, culture, value, destinationType);
            }
    
            private static void FillConstants(Hashtable hash, Type enumType)
            {
                MethodAttributes methodAttribute = MethodAttributes.FamANDAssem | MethodAttributes.Family | MethodAttributes.Public | MethodAttributes.Static;
                PropertyInfo[] properties = enumType.GetProperties();
                for (int i = 0; i < (int)properties.Length; i++)
                {
                    PropertyInfo value = properties[i];
                    if (value.PropertyType == typeof(Color))
                    {
                        MethodInfo getMethod = value.GetGetMethod();
                        if (getMethod != null && (getMethod.Attributes & methodAttribute) == methodAttribute)
                        {
                            object[] objArray = null;
                            hash[value.Name] = value.GetValue(null, objArray);
                        }
                    }
                }
            }
    
            internal static object GetNamedColor(string name)
            {
                object item = null;
                item = ColorConverter.Colors[name];
                if (item != null)
                {
                    return item;
                }
                item = ColorConverter.SystemColors[name];
                return item;
            }
    
            public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
            {
                if (ColorConverter.values == null)
                {
                    lock (ColorConverter.ValuesLock)
                    {
                        if (ColorConverter.values == null)
                        {
                            ArrayList arrayLists = new ArrayList();
                            arrayLists.AddRange(ColorConverter.Colors.Values);
                            arrayLists.AddRange(ColorConverter.SystemColors.Values);
                            int count = arrayLists.Count;
                            for (int i = 0; i < count - 1; i++)
                            {
                                for (int j = i + 1; j < count; j++)
                                {
                                    if (arrayLists[i].Equals(arrayLists[j]))
                                    {
                                        arrayLists.RemoveAt(j);
                                        count--;
                                        j--;
                                    }
                                }
                            }
                            arrayLists.Sort(0, arrayLists.Count, new ColorConverter.ColorComparer());
                            ColorConverter.values = new TypeConverter.StandardValuesCollection(arrayLists.ToArray());
                        }
                    }
                }
                return ColorConverter.values;
            }
    
            public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
            {
                return true;
            }
    
            private class ColorComparer : IComparer
            {
                public ColorComparer()
                {
                }
    
                public int Compare(object left, object right)
                {
                    Color color = (Color)left;
                    Color color1 = (Color)right;
                    return string.Compare(color.Name, color1.Name, false, CultureInfo.InvariantCulture);
                }
            }
        }
    }

    If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer

    Help by clicking:
    Click here to donate your rice to the poor
    Click to Donate
    Click to feed Dogs & Cats


    Found any spamming-senders? Please report at: Spam Report

    2013年9月4日 上午 07:15
  • 依你的情境,你要把成員宣告成常數吧。


    強力監督SQL Injection問題!!

      • 小朱的技術隨手寫:http://www.dotblogs.com.tw/regionbbs/
      • 雲端學堂Facebook: http://www.facebook.com/studyazure

    2013年9月4日 上午 07:18
    版主

所有回覆

  • 参考  http://msdn.microsoft.com/en-us/library/8h84wky1.aspx
    2013年9月4日 上午 07:08
  • 代码如下:

    Imports System
    Imports System.ComponentModel
    Imports System.Diagnostics
    Imports System.Drawing.Design
    Imports System.Globalization
    Imports System.Reflection
    Imports System.Text
    
    Namespace System.Drawing
        <DebuggerDisplay("{NameAndARGBValue}")>
        <Editor("System.Drawing.Design.ColorEditor, System.Drawing.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", GetType(UITypeEditor))>
        <Serializable>
        <TypeConverter(GetType(ColorConverter))>
        Public Structure Color
            Private Const ARGBAlphaShift As Integer = 24
    
            Private Const ARGBRedShift As Integer = 16
    
            Private Const ARGBGreenShift As Integer = 8
    
            Private Const ARGBBlueShift As Integer = 0
    
            Public ReadOnly Shared Empty As Color
    
            Private Shared StateKnownColorValid As Short
    
            Private Shared StateARGBValueValid As Short
    
            Private Shared StateValueMask As Short
    
            Private Shared StateNameValid As Short
    
            Private Shared NotDefinedValue As Long
    
            Private ReadOnly name As String
    
            Private ReadOnly value As Long
    
            Private ReadOnly knownColor As Short
    
            Private ReadOnly state As Short
    
            Public ReadOnly Property A As Byte
                Get
                    Return CByte((Me.Value >> 24 And CLng(255)))
                End Get
            End Property
    
            Public ReadOnly Shared Property AliceBlue As Color
                Get
                    Return New Color(KnownColor.AliceBlue)
                End Get
            End Property
    
            Public ReadOnly Shared Property AntiqueWhite As Color
                Get
                    Return New Color(KnownColor.AntiqueWhite)
                End Get
            End Property
    
            Public ReadOnly Shared Property Aqua As Color
                Get
                    Return New Color(KnownColor.Aqua)
                End Get
            End Property
    
            Public ReadOnly Shared Property Aquamarine As Color
                Get
                    Return New Color(KnownColor.Aquamarine)
                End Get
            End Property
    
            Public ReadOnly Shared Property Azure As Color
                Get
                    Return New Color(KnownColor.Azure)
                End Get
            End Property
    
            Public ReadOnly Property B As Byte
                Get
                    Return CByte((Me.Value And CLng(255)))
                End Get
            End Property
    
            Public ReadOnly Shared Property Beige As Color
                Get
                    Return New Color(KnownColor.Beige)
                End Get
            End Property
    
            Public ReadOnly Shared Property Bisque As Color
                Get
                    Return New Color(KnownColor.Bisque)
                End Get
            End Property
    
            Public ReadOnly Shared Property Black As Color
                Get
                    Return New Color(KnownColor.Black)
                End Get
            End Property
    
            Public ReadOnly Shared Property BlanchedAlmond As Color
                Get
                    Return New Color(KnownColor.BlanchedAlmond)
                End Get
            End Property
    
            Public ReadOnly Shared Property Blue As Color
                Get
                    Return New Color(KnownColor.Blue)
                End Get
            End Property
    
            Public ReadOnly Shared Property BlueViolet As Color
                Get
                    Return New Color(KnownColor.BlueViolet)
                End Get
            End Property
    
            Public ReadOnly Shared Property Brown As Color
                Get
                    Return New Color(KnownColor.Brown)
                End Get
            End Property
    
            Public ReadOnly Shared Property BurlyWood As Color
                Get
                    Return New Color(KnownColor.BurlyWood)
                End Get
            End Property
    
            Public ReadOnly Shared Property CadetBlue As Color
                Get
                    Return New Color(KnownColor.CadetBlue)
                End Get
            End Property
    
            Public ReadOnly Shared Property Chartreuse As Color
                Get
                    Return New Color(KnownColor.Chartreuse)
                End Get
            End Property
    
            Public ReadOnly Shared Property Chocolate As Color
                Get
                    Return New Color(KnownColor.Chocolate)
                End Get
            End Property
    
            Public ReadOnly Shared Property Coral As Color
                Get
                    Return New Color(KnownColor.Coral)
                End Get
            End Property
    
            Public ReadOnly Shared Property CornflowerBlue As Color
                Get
                    Return New Color(KnownColor.CornflowerBlue)
                End Get
            End Property
    
            Public ReadOnly Shared Property Cornsilk As Color
                Get
                    Return New Color(KnownColor.Cornsilk)
                End Get
            End Property
    
            Public ReadOnly Shared Property Crimson As Color
                Get
                    Return New Color(KnownColor.Crimson)
                End Get
            End Property
    
            Public ReadOnly Shared Property Cyan As Color
                Get
                    Return New Color(KnownColor.Cyan)
                End Get
            End Property
    
            Public ReadOnly Shared Property DarkBlue As Color
                Get
                    Return New Color(KnownColor.DarkBlue)
                End Get
            End Property
    
            Public ReadOnly Shared Property DarkCyan As Color
                Get
                    Return New Color(KnownColor.DarkCyan)
                End Get
            End Property
    
            Public ReadOnly Shared Property DarkGoldenrod As Color
                Get
                    Return New Color(KnownColor.DarkGoldenrod)
                End Get
            End Property
    
            Public ReadOnly Shared Property DarkGray As Color
                Get
                    Return New Color(KnownColor.DarkGray)
                End Get
            End Property
    
            Public ReadOnly Shared Property DarkGreen As Color
                Get
                    Return New Color(KnownColor.DarkGreen)
                End Get
            End Property
    
            Public ReadOnly Shared Property DarkKhaki As Color
                Get
                    Return New Color(KnownColor.DarkKhaki)
                End Get
            End Property
    
            Public ReadOnly Shared Property DarkMagenta As Color
                Get
                    Return New Color(KnownColor.DarkMagenta)
                End Get
            End Property
    
            Public ReadOnly Shared Property DarkOliveGreen As Color
                Get
                    Return New Color(KnownColor.DarkOliveGreen)
                End Get
            End Property
    
            Public ReadOnly Shared Property DarkOrange As Color
                Get
                    Return New Color(KnownColor.DarkOrange)
                End Get
            End Property
    
            Public ReadOnly Shared Property DarkOrchid As Color
                Get
                    Return New Color(KnownColor.DarkOrchid)
                End Get
            End Property
    
            Public ReadOnly Shared Property DarkRed As Color
                Get
                    Return New Color(KnownColor.DarkRed)
                End Get
            End Property
    
            Public ReadOnly Shared Property DarkSalmon As Color
                Get
                    Return New Color(KnownColor.DarkSalmon)
                End Get
            End Property
    
            Public ReadOnly Shared Property DarkSeaGreen As Color
                Get
                    Return New Color(KnownColor.DarkSeaGreen)
                End Get
            End Property
    
            Public ReadOnly Shared Property DarkSlateBlue As Color
                Get
                    Return New Color(KnownColor.DarkSlateBlue)
                End Get
            End Property
    
            Public ReadOnly Shared Property DarkSlateGray As Color
                Get
                    Return New Color(KnownColor.DarkSlateGray)
                End Get
            End Property
    
            Public ReadOnly Shared Property DarkTurquoise As Color
                Get
                    Return New Color(KnownColor.DarkTurquoise)
                End Get
            End Property
    
            Public ReadOnly Shared Property DarkViolet As Color
                Get
                    Return New Color(KnownColor.DarkViolet)
                End Get
            End Property
    
            Public ReadOnly Shared Property DeepPink As Color
                Get
                    Return New Color(KnownColor.DeepPink)
                End Get
            End Property
    
            Public ReadOnly Shared Property DeepSkyBlue As Color
                Get
                    Return New Color(KnownColor.DeepSkyBlue)
                End Get
            End Property
    
            Public ReadOnly Shared Property DimGray As Color
                Get
                    Return New Color(KnownColor.DimGray)
                End Get
            End Property
    
            Public ReadOnly Shared Property DodgerBlue As Color
                Get
                    Return New Color(KnownColor.DodgerBlue)
                End Get
            End Property
    
            Public ReadOnly Shared Property Firebrick As Color
                Get
                    Return New Color(KnownColor.Firebrick)
                End Get
            End Property
    
            Public ReadOnly Shared Property FloralWhite As Color
                Get
                    Return New Color(KnownColor.FloralWhite)
                End Get
            End Property
    
            Public ReadOnly Shared Property ForestGreen As Color
                Get
                    Return New Color(KnownColor.ForestGreen)
                End Get
            End Property
    
            Public ReadOnly Shared Property Fuchsia As Color
                Get
                    Return New Color(KnownColor.Fuchsia)
                End Get
            End Property
    
            Public ReadOnly Property G As Byte
                Get
                    Return CByte((Me.Value >> 8 And CLng(255)))
                End Get
            End Property
    
            Public ReadOnly Shared Property Gainsboro As Color
                Get
                    Return New Color(KnownColor.Gainsboro)
                End Get
            End Property
    
            Public ReadOnly Shared Property GhostWhite As Color
                Get
                    Return New Color(KnownColor.GhostWhite)
                End Get
            End Property
    
            Public ReadOnly Shared Property Gold As Color
                Get
                    Return New Color(KnownColor.Gold)
                End Get
            End Property
    
            Public ReadOnly Shared Property Goldenrod As Color
                Get
                    Return New Color(KnownColor.Goldenrod)
                End Get
            End Property
    
            Public ReadOnly Shared Property Gray As Color
                Get
                    Return New Color(KnownColor.Gray)
                End Get
            End Property
    
            Public ReadOnly Shared Property Green As Color
                Get
                    Return New Color(KnownColor.Green)
                End Get
            End Property
    
            Public ReadOnly Shared Property GreenYellow As Color
                Get
                    Return New Color(KnownColor.GreenYellow)
                End Get
            End Property
    
            Public ReadOnly Shared Property Honeydew As Color
                Get
                    Return New Color(KnownColor.Honeydew)
                End Get
            End Property
    
            Public ReadOnly Shared Property HotPink As Color
                Get
                    Return New Color(KnownColor.HotPink)
                End Get
            End Property
    
            Public ReadOnly Shared Property IndianRed As Color
                Get
                    Return New Color(KnownColor.IndianRed)
                End Get
            End Property
    
            Public ReadOnly Shared Property Indigo As Color
                Get
                    Return New Color(KnownColor.Indigo)
                End Get
            End Property
    
            Public ReadOnly Property IsEmpty As Boolean
                Get
                    Return Me.state = 0
                End Get
            End Property
    
            Public ReadOnly Property IsKnownColor As Boolean
                Get
                    Return (Me.state And Color.StateKnownColorValid) <> 0
                End Get
            End Property
    
            Public ReadOnly Property IsNamedColor As Boolean
                Get
                    If ((Me.state And Color.StateNameValid) <> 0) Then
                        Return True
                    End If
                    Return Me.IsKnownColor
                End Get
            End Property
    
            Public ReadOnly Property IsSystemColor As Boolean
                Get
                    If (Not Me.IsKnownColor) Then
                        Return False
                    End If
                    If (Me.knownColor <= 26) Then
                        Return True
                    End If
                    Return Me.knownColor > 167
                End Get
            End Property
    
            Public ReadOnly Shared Property Ivory As Color
                Get
                    Return New Color(KnownColor.Ivory)
                End Get
            End Property
    
            Public ReadOnly Shared Property Khaki As Color
                Get
                    Return New Color(KnownColor.Khaki)
                End Get
            End Property
    
            Public ReadOnly Shared Property Lavender As Color
                Get
                    Return New Color(KnownColor.Lavender)
                End Get
            End Property
    
            Public ReadOnly Shared Property LavenderBlush As Color
                Get
                    Return New Color(KnownColor.LavenderBlush)
                End Get
            End Property
    
            Public ReadOnly Shared Property LawnGreen As Color
                Get
                    Return New Color(KnownColor.LawnGreen)
                End Get
            End Property
    
            Public ReadOnly Shared Property LemonChiffon As Color
                Get
                    Return New Color(KnownColor.LemonChiffon)
                End Get
            End Property
    
            Public ReadOnly Shared Property LightBlue As Color
                Get
                    Return New Color(KnownColor.LightBlue)
                End Get
            End Property
    
            Public ReadOnly Shared Property LightCoral As Color
                Get
                    Return New Color(KnownColor.LightCoral)
                End Get
            End Property
    
            Public ReadOnly Shared Property LightCyan As Color
                Get
                    Return New Color(KnownColor.LightCyan)
                End Get
            End Property
    
            Public ReadOnly Shared Property LightGoldenrodYellow As Color
                Get
                    Return New Color(KnownColor.LightGoldenrodYellow)
                End Get
            End Property
    
            Public ReadOnly Shared Property LightGray As Color
                Get
                    Return New Color(KnownColor.LightGray)
                End Get
            End Property
    
            Public ReadOnly Shared Property LightGreen As Color
                Get
                    Return New Color(KnownColor.LightGreen)
                End Get
            End Property
    
            Public ReadOnly Shared Property LightPink As Color
                Get
                    Return New Color(KnownColor.LightPink)
                End Get
            End Property
    
            Public ReadOnly Shared Property LightSalmon As Color
                Get
                    Return New Color(KnownColor.LightSalmon)
                End Get
            End Property
    
            Public ReadOnly Shared Property LightSeaGreen As Color
                Get
                    Return New Color(KnownColor.LightSeaGreen)
                End Get
            End Property
    
            Public ReadOnly Shared Property LightSkyBlue As Color
                Get
                    Return New Color(KnownColor.LightSkyBlue)
                End Get
            End Property
    
            Public ReadOnly Shared Property LightSlateGray As Color
                Get
                    Return New Color(KnownColor.LightSlateGray)
                End Get
            End Property
    
            Public ReadOnly Shared Property LightSteelBlue As Color
                Get
                    Return New Color(KnownColor.LightSteelBlue)
                End Get
            End Property
    
            Public ReadOnly Shared Property LightYellow As Color
                Get
                    Return New Color(KnownColor.LightYellow)
                End Get
            End Property
    
            Public ReadOnly Shared Property Lime As Color
                Get
                    Return New Color(KnownColor.Lime)
                End Get
            End Property
    
            Public ReadOnly Shared Property LimeGreen As Color
                Get
                    Return New Color(KnownColor.LimeGreen)
                End Get
            End Property
    
            Public ReadOnly Shared Property Linen As Color
                Get
                    Return New Color(KnownColor.Linen)
                End Get
            End Property
    
            Public ReadOnly Shared Property Magenta As Color
                Get
                    Return New Color(KnownColor.Magenta)
                End Get
            End Property
    
            Public ReadOnly Shared Property Maroon As Color
                Get
                    Return New Color(KnownColor.Maroon)
                End Get
            End Property
    
            Public ReadOnly Shared Property MediumAquamarine As Color
                Get
                    Return New Color(KnownColor.MediumAquamarine)
                End Get
            End Property
    
            Public ReadOnly Shared Property MediumBlue As Color
                Get
                    Return New Color(KnownColor.MediumBlue)
                End Get
            End Property
    
            Public ReadOnly Shared Property MediumOrchid As Color
                Get
                    Return New Color(KnownColor.MediumOrchid)
                End Get
            End Property
    
            Public ReadOnly Shared Property MediumPurple As Color
                Get
                    Return New Color(KnownColor.MediumPurple)
                End Get
            End Property
    
            Public ReadOnly Shared Property MediumSeaGreen As Color
                Get
                    Return New Color(KnownColor.MediumSeaGreen)
                End Get
            End Property
    
            Public ReadOnly Shared Property MediumSlateBlue As Color
                Get
                    Return New Color(KnownColor.MediumSlateBlue)
                End Get
            End Property
    
            Public ReadOnly Shared Property MediumSpringGreen As Color
                Get
                    Return New Color(KnownColor.MediumSpringGreen)
                End Get
            End Property
    
            Public ReadOnly Shared Property MediumTurquoise As Color
                Get
                    Return New Color(KnownColor.MediumTurquoise)
                End Get
            End Property
    
            Public ReadOnly Shared Property MediumVioletRed As Color
                Get
                    Return New Color(KnownColor.MediumVioletRed)
                End Get
            End Property
    
            Public ReadOnly Shared Property MidnightBlue As Color
                Get
                    Return New Color(KnownColor.MidnightBlue)
                End Get
            End Property
    
            Public ReadOnly Shared Property MintCream As Color
                Get
                    Return New Color(KnownColor.MintCream)
                End Get
            End Property
    
            Public ReadOnly Shared Property MistyRose As Color
                Get
                    Return New Color(KnownColor.MistyRose)
                End Get
            End Property
    
            Public ReadOnly Shared Property Moccasin As Color
                Get
                    Return New Color(KnownColor.Moccasin)
                End Get
            End Property
    
            Public ReadOnly Property Name As String
                Get
                    If ((Me.state And Color.StateNameValid) <> 0) Then
                        Return Me.name
                    End If
                    If (Not Me.IsKnownColor) Then
                        Return Convert.ToString(Me.value, 16)
                    End If
                    Dim name As String = KnownColorTable.KnownColorToName(DirectCast(Me.knownColor, KnownColor))
                    If (name IsNot Nothing) Then
                        Return name
                    End If
                    Return DirectCast(Me.knownColor, KnownColor).ToString()
                End Get
            End Property
    
            Private ReadOnly Property NameAndARGBValue As String
                Get
                    Dim currentCulture As CultureInfo = CultureInfo.CurrentCulture
                    Dim name() As Object = { Me.Name, Me.A, Me.R, Me.G, Me.B }
                    Return String.Format(currentCulture, "{{Name={0}, ARGB=({1}, {2}, {3}, {4})}}", name)
                End Get
            End Property
    
            Public ReadOnly Shared Property NavajoWhite As Color
                Get
                    Return New Color(KnownColor.NavajoWhite)
                End Get
            End Property
    
            Public ReadOnly Shared Property Navy As Color
                Get
                    Return New Color(KnownColor.Navy)
                End Get
            End Property
    
            Public ReadOnly Shared Property OldLace As Color
                Get
                    Return New Color(KnownColor.OldLace)
                End Get
            End Property
    
            Public ReadOnly Shared Property Olive As Color
                Get
                    Return New Color(KnownColor.Olive)
                End Get
            End Property
    
            Public ReadOnly Shared Property OliveDrab As Color
                Get
                    Return New Color(KnownColor.OliveDrab)
                End Get
            End Property
    
            Public ReadOnly Shared Property Orange As Color
                Get
                    Return New Color(KnownColor.Orange)
                End Get
            End Property
    
            Public ReadOnly Shared Property OrangeRed As Color
                Get
                    Return New Color(KnownColor.OrangeRed)
                End Get
            End Property
    
            Public ReadOnly Shared Property Orchid As Color
                Get
                    Return New Color(KnownColor.Orchid)
                End Get
            End Property
    
            Public ReadOnly Shared Property PaleGoldenrod As Color
                Get
                    Return New Color(KnownColor.PaleGoldenrod)
                End Get
            End Property
    
            Public ReadOnly Shared Property PaleGreen As Color
                Get
                    Return New Color(KnownColor.PaleGreen)
                End Get
            End Property
    
            Public ReadOnly Shared Property PaleTurquoise As Color
                Get
                    Return New Color(KnownColor.PaleTurquoise)
                End Get
            End Property
    
            Public ReadOnly Shared Property PaleVioletRed As Color
                Get
                    Return New Color(KnownColor.PaleVioletRed)
                End Get
            End Property
    
            Public ReadOnly Shared Property PapayaWhip As Color
                Get
                    Return New Color(KnownColor.PapayaWhip)
                End Get
            End Property
    
            Public ReadOnly Shared Property PeachPuff As Color
                Get
                    Return New Color(KnownColor.PeachPuff)
                End Get
            End Property
    
            Public ReadOnly Shared Property Peru As Color
                Get
                    Return New Color(KnownColor.Peru)
                End Get
            End Property
    
            Public ReadOnly Shared Property Pink As Color
                Get
                    Return New Color(KnownColor.Pink)
                End Get
            End Property
    
            Public ReadOnly Shared Property Plum As Color
                Get
                    Return New Color(KnownColor.Plum)
                End Get
            End Property
    
            Public ReadOnly Shared Property PowderBlue As Color
                Get
                    Return New Color(KnownColor.PowderBlue)
                End Get
            End Property
    
            Public ReadOnly Shared Property Purple As Color
                Get
                    Return New Color(KnownColor.Purple)
                End Get
            End Property
    
            Public ReadOnly Property R As Byte
                Get
                    Return CByte((Me.Value >> 16 And CLng(255)))
                End Get
            End Property
    
            Public ReadOnly Shared Property Red As Color
                Get
                    Return New Color(KnownColor.Red)
                End Get
            End Property
    
            Public ReadOnly Shared Property RosyBrown As Color
                Get
                    Return New Color(KnownColor.RosyBrown)
                End Get
            End Property
    
            Public ReadOnly Shared Property RoyalBlue As Color
                Get
                    Return New Color(KnownColor.RoyalBlue)
                End Get
            End Property
    
            Public ReadOnly Shared Property SaddleBrown As Color
                Get
                    Return New Color(KnownColor.SaddleBrown)
                End Get
            End Property
    
            Public ReadOnly Shared Property Salmon As Color
                Get
                    Return New Color(KnownColor.Salmon)
                End Get
            End Property
    
            Public ReadOnly Shared Property SandyBrown As Color
                Get
                    Return New Color(KnownColor.SandyBrown)
                End Get
            End Property
    
            Public ReadOnly Shared Property SeaGreen As Color
                Get
                    Return New Color(KnownColor.SeaGreen)
                End Get
            End Property
    
            Public ReadOnly Shared Property SeaShell As Color
                Get
                    Return New Color(KnownColor.SeaShell)
                End Get
            End Property
    
            Public ReadOnly Shared Property Sienna As Color
                Get
                    Return New Color(KnownColor.Sienna)
                End Get
            End Property
    
            Public ReadOnly Shared Property Silver As Color
                Get
                    Return New Color(KnownColor.Silver)
                End Get
            End Property
    
            Public ReadOnly Shared Property SkyBlue As Color
                Get
                    Return New Color(KnownColor.SkyBlue)
                End Get
            End Property
    
            Public ReadOnly Shared Property SlateBlue As Color
                Get
                    Return New Color(KnownColor.SlateBlue)
                End Get
            End Property
    
            Public ReadOnly Shared Property SlateGray As Color
                Get
                    Return New Color(KnownColor.SlateGray)
                End Get
            End Property
    
            Public ReadOnly Shared Property Snow As Color
                Get
                    Return New Color(KnownColor.Snow)
                End Get
            End Property
    
            Public ReadOnly Shared Property SpringGreen As Color
                Get
                    Return New Color(KnownColor.SpringGreen)
                End Get
            End Property
    
            Public ReadOnly Shared Property SteelBlue As Color
                Get
                    Return New Color(KnownColor.SteelBlue)
                End Get
            End Property
    
            Public ReadOnly Shared Property Tan As Color
                Get
                    Return New Color(KnownColor.Tan)
                End Get
            End Property
    
            Public ReadOnly Shared Property Teal As Color
                Get
                    Return New Color(KnownColor.Teal)
                End Get
            End Property
    
            Public ReadOnly Shared Property Thistle As Color
                Get
                    Return New Color(KnownColor.Thistle)
                End Get
            End Property
    
            Public ReadOnly Shared Property Tomato As Color
                Get
                    Return New Color(KnownColor.Tomato)
                End Get
            End Property
    
            Public ReadOnly Shared Property Transparent As Color
                Get
                    Return New Color(KnownColor.Transparent)
                End Get
            End Property
    
            Public ReadOnly Shared Property Turquoise As Color
                Get
                    Return New Color(KnownColor.Turquoise)
                End Get
            End Property
    
            Private ReadOnly Property Value As Long
                Get
                    If ((Me.state And Color.StateValueMask) <> 0) Then
                        Return Me.value
                    End If
                    If (Not Me.IsKnownColor) Then
                        Return Color.NotDefinedValue
                    End If
                    Return CLng(KnownColorTable.KnownColorToArgb(DirectCast(Me.knownColor, KnownColor)))
                End Get
            End Property
    
            Public ReadOnly Shared Property Violet As Color
                Get
                    Return New Color(KnownColor.Violet)
                End Get
            End Property
    
            Public ReadOnly Shared Property Wheat As Color
                Get
                    Return New Color(KnownColor.Wheat)
                End Get
            End Property
    
            Public ReadOnly Shared Property White As Color
                Get
                    Return New Color(KnownColor.White)
                End Get
            End Property
    
            Public ReadOnly Shared Property WhiteSmoke As Color
                Get
                    Return New Color(KnownColor.WhiteSmoke)
                End Get
            End Property
    
            Public ReadOnly Shared Property Yellow As Color
                Get
                    Return New Color(KnownColor.Yellow)
                End Get
            End Property
    
            Public ReadOnly Shared Property YellowGreen As Color
                Get
                    Return New Color(KnownColor.YellowGreen)
                End Get
            End Property
    
            Shared Sub New()
                Color.Empty = New Color()
                Color.StateKnownColorValid = 1
                Color.StateARGBValueValid = 2
                Color.StateValueMask = Color.StateARGBValueValid
                Color.StateNameValid = 8
                Color.NotDefinedValue = CLng(0)
            End Sub
    
            Friend Sub New(ByVal knownColor As System.Drawing.KnownColor)
                Me.value = CLng(0)
                Me.state = Color.StateKnownColorValid
                Me.name = Nothing
                Me.knownColor = CShort(knownColor)
            End Sub
    
            Private Sub New(ByVal value As Long, ByVal state As Short, ByVal name As String, ByVal knownColor As System.Drawing.KnownColor)
                Me.value = value
                Me.state = state
                Me.name = name
                Me.knownColor = CShort(knownColor)
            End Sub
    
            Private Shared Sub CheckByte(ByVal value As Integer, ByVal name As String)
                If (value < 0 OrElse value > 255) Then
                    Dim objArray() As Object = { name, value, 0, 255 }
                    Throw New ArgumentException(SR.GetString("InvalidEx2BoundArgument", objArray))
                End If
            End Sub
    
            Public Overrides Function Equals(ByVal obj As Object) As Boolean
                If (TypeOf obj Is System.Drawing.Color) Then
                    Dim color As System.Drawing.Color = DirectCast(obj, System.Drawing.Color)
                    If (Me.value = color.value AndAlso Me.state = color.state AndAlso Me.knownColor = color.knownColor) Then
                        If (Me.name = color.name) Then
                            Return True
                        End If
                        If (Me.name Is Nothing OrElse color.name Is Nothing) Then
                            Return False
                        End If
                        Return Me.name.Equals(Me.name)
                    End If
                End If
                Return False
            End Function
    
            Public Shared Function FromArgb(ByVal argb As Integer) As Color
                Return New Color(CLng((CLng(argb) And DirectCast(-1, ULong))), Color.StateARGBValueValid, Nothing, 0)
            End Function
    
            Public Shared Function FromArgb(ByVal alpha As Integer, ByVal red As Integer, ByVal green As Integer, ByVal blue As Integer) As Color
                Color.CheckByte(alpha, "alpha")
                Color.CheckByte(red, "red")
                Color.CheckByte(green, "green")
                Color.CheckByte(blue, "blue")
                Return New Color(Color.MakeArgb(CByte(alpha), CByte(red), CByte(green), CByte(blue)), Color.StateARGBValueValid, Nothing, 0)
            End Function
    
            Public Shared Function FromArgb(ByVal alpha As Integer, ByVal baseColor As Color) As Color
                Color.CheckByte(alpha, "alpha")
                Return New Color(Color.MakeArgb(CByte(alpha), baseColor.R, baseColor.G, baseColor.B), Color.StateARGBValueValid, Nothing, 0)
            End Function
    
            Public Shared Function FromArgb(ByVal red As Integer, ByVal green As Integer, ByVal blue As Integer) As Color
                Return Color.FromArgb(255, red, green, blue)
            End Function
    
            Public Shared Function FromKnownColor(ByVal color As KnownColor) As System.Drawing.Color
                If (ClientUtils.IsEnumValid(color, CInt(color), 1, 174)) Then
                    Return New System.Drawing.Color(color)
                End If
                Return System.Drawing.Color.FromName(color.ToString())
            End Function
    
            Public Shared Function FromName(ByVal name As String) As Color
                Dim namedColor As Object = ColorConverter.GetNamedColor(name)
                If (namedColor IsNot Nothing) Then
                    Return DirectCast(namedColor, Color)
                End If
                Return New Color(Color.NotDefinedValue, Color.StateNameValid, name, 0)
            End Function
    
            Public Function GetBrightness() As Single
                Dim r As Single = CSng(Me.R) / 255!
                Dim g As Single = CSng(Me.G) / 255!
                Dim b As Single = CSng(Me.B) / 255!
                Dim [single] As Single = r
                Dim single1 As Single = r
                If (g > [single]) Then
                    [single] = g
                End If
                If (b > [single]) Then
                    [single] = b
                End If
                If (g < single1) Then
                    single1 = g
                End If
                If (b < single1) Then
                    single1 = b
                End If
                Return ([single] + single1) / 2!
            End Function
    
            Public Overrides Function GetHashCode() As Integer
                Return Me.value.GetHashCode() Xor Me.state.GetHashCode() Xor Me.knownColor.GetHashCode()
            End Function
    
            Public Function GetHue() As Single
                If (Me.R = Me.G AndAlso Me.G = Me.B) Then
                    Return 0!
                End If
                Dim r As Single = CSng(Me.R) / 255!
                Dim g As Single = CSng(Me.G) / 255!
                Dim b As Single = CSng(Me.B) / 255!
                Dim [single] As Single = 0!
                Dim single1 As Single = r
                Dim single2 As Single = r
                If (g > single1) Then
                    single1 = g
                End If
                If (b > single1) Then
                    single1 = b
                End If
                If (g < single2) Then
                    single2 = g
                End If
                If (b < single2) Then
                    single2 = b
                End If
                Dim single3 As Single = single1 - single2
                If (r = single1) Then
                    [single] = (g - b) / single3
                ElseIf (g = single1) Then
                    [single] = 2! + (b - r) / single3
                ElseIf (b = single1) Then
                    [single] = 4! + (r - g) / single3
                End If
                [single] = [single] * 60!
                If ([single] < 0!) Then
                    [single] = [single] + 360!
                End If
                Return [single]
            End Function
    
            Public Function GetSaturation() As Single
                Dim r As Single = CSng(Me.R) / 255!
                Dim g As Single = CSng(Me.G) / 255!
                Dim b As Single = CSng(Me.B) / 255!
                Dim [single] As Single = 0!
                Dim single1 As Single = r
                Dim single2 As Single = r
                If (g > single1) Then
                    single1 = g
                End If
                If (b > single1) Then
                    single1 = b
                End If
                If (g < single2) Then
                    single2 = g
                End If
                If (b < single2) Then
                    single2 = b
                End If
                If (single1 <> single2) Then
                    [single] = If(CDbl(((single1 + single2) / 2!)) > 0.5, (single1 - single2) / (2! - single1 - single2), (single1 - single2) / (single1 + single2))
                End If
                Return [single]
            End Function
    
            Private Shared Function MakeArgb(ByVal alpha As Byte, ByVal red As Byte, ByVal green As Byte, ByVal blue As Byte) As Long
                Return CLng((DirectCast((red << 16 Or green << 8 Or blue Or alpha << 24), ULong) And DirectCast(-1, ULong)))
            End Function
    
            Public Shared Operator =(ByVal left As Color, ByVal right As Color) As Boolean
                If (left.value <> right.value OrElse left.state <> right.state OrElse left.knownColor <> right.knownColor) Then
                    Return False
                End If
                If (left.name = right.name) Then
                    Return True
                End If
                If (left.name Is Nothing OrElse right.name Is Nothing) Then
                    Return False
                End If
                Return left.name.Equals(right.name)
            End Operator
    
            Public Shared Operator <>(ByVal left As Color, ByVal right As Color) As Boolean
                Return Not (left = right)
            End Operator
    
            Public Function ToArgb() As Integer
                Return CInt(Me.Value)
            End Function
    
            Public Function ToKnownColor() As KnownColor
                Return DirectCast(Me.knownColor, KnownColor)
            End Function
    
            Public Overrides Function ToString() As String
                Dim stringBuilder As System.Text.StringBuilder = New System.Text.StringBuilder(32)
                stringBuilder.Append(Me.[GetType]().Name)
                stringBuilder.Append(" [")
                If ((Me.state And Color.StateNameValid) <> 0) Then
                    stringBuilder.Append(Me.Name)
                ElseIf ((Me.state And Color.StateKnownColorValid) <> 0) Then
                    stringBuilder.Append(Me.Name)
                ElseIf ((Me.state And Color.StateValueMask) = 0) Then
                    stringBuilder.Append("Empty")
                Else
                    stringBuilder.Append("A=")
                    stringBuilder.Append(Me.A)
                    stringBuilder.Append(", R=")
                    stringBuilder.Append(Me.R)
                    stringBuilder.Append(", G=")
                    stringBuilder.Append(Me.G)
                    stringBuilder.Append(", B=")
                    stringBuilder.Append(Me.B)
                End If
                stringBuilder.Append("]")
                Return stringBuilder.ToString()
            End Function
        End Structure
    End Namespace
    ColorConverter代码:
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.ComponentModel.Design.Serialization;
    using System.Globalization;
    using System.Reflection;
    
    namespace System.Drawing
    {
        public class ColorConverter : TypeConverter
        {
            private static string ColorConstantsLock;
    
            private static Hashtable colorConstants;
    
            private static string SystemColorConstantsLock;
    
            private static Hashtable systemColorConstants;
    
            private static string ValuesLock;
    
            private static TypeConverter.StandardValuesCollection values;
    
            private static Hashtable Colors
            {
                get
                {
                    if (ColorConverter.colorConstants == null)
                    {
                        lock (ColorConverter.ColorConstantsLock)
                        {
                            if (ColorConverter.colorConstants == null)
                            {
                                Hashtable hashtables = new Hashtable(StringComparer.OrdinalIgnoreCase);
                                ColorConverter.FillConstants(hashtables, typeof(Color));
                                ColorConverter.colorConstants = hashtables;
                            }
                        }
                    }
                    return ColorConverter.colorConstants;
                }
            }
    
            private static Hashtable SystemColors
            {
                get
                {
                    if (ColorConverter.systemColorConstants == null)
                    {
                        lock (ColorConverter.SystemColorConstantsLock)
                        {
                            if (ColorConverter.systemColorConstants == null)
                            {
                                Hashtable hashtables = new Hashtable(StringComparer.OrdinalIgnoreCase);
                                ColorConverter.FillConstants(hashtables, typeof(SystemColors));
                                ColorConverter.systemColorConstants = hashtables;
                            }
                        }
                    }
                    return ColorConverter.systemColorConstants;
                }
            }
    
            static ColorConverter()
            {
                ColorConverter.ColorConstantsLock = "colorConstants";
                ColorConverter.SystemColorConstantsLock = "systemColorConstants";
                ColorConverter.ValuesLock = "values";
            }
    
            public ColorConverter()
            {
            }
    
            public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
            {
                if (sourceType == typeof(string))
                {
                    return true;
                }
                return base.CanConvertFrom(context, sourceType);
            }
    
            public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
            {
                if (destinationType == typeof(InstanceDescriptor))
                {
                    return true;
                }
                return base.CanConvertTo(context, destinationType);
            }
    
            public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
            {
                string str = value as string;
                if (str == null)
                {
                    return base.ConvertFrom(context, culture, value);
                }
                object namedColor = null;
                string str1 = str.Trim();
                if (str1.Length != 0)
                {
                    namedColor = ColorConverter.GetNamedColor(str1);
                    if (namedColor == null)
                    {
                        if (culture == null)
                        {
                            culture = CultureInfo.CurrentCulture;
                        }
                        char listSeparator = culture.TextInfo.ListSeparator[0];
                        bool flag = true;
                        TypeConverter converter = TypeDescriptor.GetConverter(typeof(int));
                        if (str1.IndexOf(listSeparator) == -1)
                        {
                            if (str1.Length >= 2 && (str1[0] == '\'' || str1[0] == '\"') && str1[0] == str1[str1.Length - 1])
                            {
                                string str2 = str1.Substring(1, str1.Length - 2);
                                namedColor = Color.FromName(str2);
                                flag = false;
                            }
                            else if (str1.Length == 7 && str1[0] == '#' || str1.Length == 8 && (str1.StartsWith("0x") || str1.StartsWith("0X")) || str1.Length == 8 && (str1.StartsWith("&h") || str1.StartsWith("&H")))
                            {
                                namedColor = Color.FromArgb(-16777216 | (int)converter.ConvertFromString(context, culture, str1));
                            }
                        }
                        if (namedColor == null)
                        {
                            string[] strArrays = str1.Split(new char[] { listSeparator });
                            int[] numArray = new int[(int)strArrays.Length];
                            for (int i = 0; i < (int)numArray.Length; i++)
                            {
                                numArray[i] = (int)converter.ConvertFromString(context, culture, strArrays[i]);
                            }
                            switch ((int)numArray.Length)
                            {
                                case 1:
                                {
                                    namedColor = Color.FromArgb(numArray[0]);
                                    goto case 2;
                                }
                                case 2:
                                {
                                    flag = true;
                                    break;
                                }
                                case 3:
                                {
                                    namedColor = Color.FromArgb(numArray[0], numArray[1], numArray[2]);
                                    goto case 2;
                                }
                                case 4:
                                {
                                    namedColor = Color.FromArgb(numArray[0], numArray[1], numArray[2], numArray[3]);
                                    goto case 2;
                                }
                                default:
                                {
                                    goto case 2;
                                }
                            }
                        }
                        if (namedColor != null && flag)
                        {
                            int argb = ((Color)namedColor).ToArgb();
                            foreach (Color color in ColorConverter.Colors.Values)
                            {
                                if (color.ToArgb() != argb)
                                {
                                    continue;
                                }
                                namedColor = color;
                                break;
                            }
                        }
                    }
                    if (namedColor == null)
                    {
                        object[] objArray = new object[] { str1 };
                        throw new ArgumentException(SR.GetString("InvalidColor", objArray));
                    }
                }
                else
                {
                    namedColor = Color.Empty;
                }
                return namedColor;
            }
    
            public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
            {
                string[] str;
                if (destinationType == null)
                {
                    throw new ArgumentNullException("destinationType");
                }
                if (value is Color)
                {
                    if (destinationType == typeof(string))
                    {
                        Color color = (Color)value;
                        if (color == Color.Empty)
                        {
                            return string.Empty;
                        }
                        if (color.IsKnownColor)
                        {
                            return color.Name;
                        }
                        if (color.IsNamedColor)
                        {
                            return string.Concat("'", color.Name, "'");
                        }
                        if (culture == null)
                        {
                            culture = CultureInfo.CurrentCulture;
                        }
                        string str1 = string.Concat(culture.TextInfo.ListSeparator, " ");
                        TypeConverter converter = TypeDescriptor.GetConverter(typeof(int));
                        int num = 0;
                        if (color.A >= 255)
                        {
                            str = new string[3];
                        }
                        else
                        {
                            str = new string[4];
                            int num1 = num;
                            num = num1 + 1;
                            str[num1] = converter.ConvertToString(context, culture, color.A);
                        }
                        int num2 = num;
                        num = num2 + 1;
                        str[num2] = converter.ConvertToString(context, culture, color.R);
                        int num3 = num;
                        num = num3 + 1;
                        str[num3] = converter.ConvertToString(context, culture, color.G);
                        int num4 = num;
                        num = num4 + 1;
                        str[num4] = converter.ConvertToString(context, culture, color.B);
                        return string.Join(str1, str);
                    }
                    if (destinationType == typeof(InstanceDescriptor))
                    {
                        MemberInfo field = null;
                        object[] name = null;
                        Color color1 = (Color)value;
                        if (color1.IsEmpty)
                        {
                            field = typeof(Color).GetField("Empty");
                        }
                        else if (color1.IsSystemColor)
                        {
                            field = typeof(SystemColors).GetProperty(color1.Name);
                        }
                        else if (color1.IsKnownColor)
                        {
                            field = typeof(Color).GetProperty(color1.Name);
                        }
                        else if (color1.A != 255)
                        {
                            Type type = typeof(Color);
                            Type[] typeArray = new Type[] { typeof(int), typeof(int), typeof(int), typeof(int) };
                            field = type.GetMethod("FromArgb", typeArray);
                            object[] a = new object[] { color1.A, color1.R, color1.G, color1.B };
                            name = a;
                        }
                        else if (!color1.IsNamedColor)
                        {
                            Type type1 = typeof(Color);
                            Type[] typeArray1 = new Type[] { typeof(int), typeof(int), typeof(int) };
                            field = type1.GetMethod("FromArgb", typeArray1);
                            object[] r = new object[] { color1.R, color1.G, color1.B };
                            name = r;
                        }
                        else
                        {
                            Type type2 = typeof(Color);
                            Type[] typeArray2 = new Type[] { typeof(string) };
                            field = type2.GetMethod("FromName", typeArray2);
                            name = new object[] { color1.Name };
                        }
                        if (field == null)
                        {
                            return null;
                        }
                        return new InstanceDescriptor(field, name);
                    }
                }
                return base.ConvertTo(context, culture, value, destinationType);
            }
    
            private static void FillConstants(Hashtable hash, Type enumType)
            {
                MethodAttributes methodAttribute = MethodAttributes.FamANDAssem | MethodAttributes.Family | MethodAttributes.Public | MethodAttributes.Static;
                PropertyInfo[] properties = enumType.GetProperties();
                for (int i = 0; i < (int)properties.Length; i++)
                {
                    PropertyInfo value = properties[i];
                    if (value.PropertyType == typeof(Color))
                    {
                        MethodInfo getMethod = value.GetGetMethod();
                        if (getMethod != null && (getMethod.Attributes & methodAttribute) == methodAttribute)
                        {
                            object[] objArray = null;
                            hash[value.Name] = value.GetValue(null, objArray);
                        }
                    }
                }
            }
    
            internal static object GetNamedColor(string name)
            {
                object item = null;
                item = ColorConverter.Colors[name];
                if (item != null)
                {
                    return item;
                }
                item = ColorConverter.SystemColors[name];
                return item;
            }
    
            public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
            {
                if (ColorConverter.values == null)
                {
                    lock (ColorConverter.ValuesLock)
                    {
                        if (ColorConverter.values == null)
                        {
                            ArrayList arrayLists = new ArrayList();
                            arrayLists.AddRange(ColorConverter.Colors.Values);
                            arrayLists.AddRange(ColorConverter.SystemColors.Values);
                            int count = arrayLists.Count;
                            for (int i = 0; i < count - 1; i++)
                            {
                                for (int j = i + 1; j < count; j++)
                                {
                                    if (arrayLists[i].Equals(arrayLists[j]))
                                    {
                                        arrayLists.RemoveAt(j);
                                        count--;
                                        j--;
                                    }
                                }
                            }
                            arrayLists.Sort(0, arrayLists.Count, new ColorConverter.ColorComparer());
                            ColorConverter.values = new TypeConverter.StandardValuesCollection(arrayLists.ToArray());
                        }
                    }
                }
                return ColorConverter.values;
            }
    
            public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
            {
                return true;
            }
    
            private class ColorComparer : IComparer
            {
                public ColorComparer()
                {
                }
    
                public int Compare(object left, object right)
                {
                    Color color = (Color)left;
                    Color color1 = (Color)right;
                    return string.Compare(color.Name, color1.Name, false, CultureInfo.InvariantCulture);
                }
            }
        }
    }

    If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer

    Help by clicking:
    Click here to donate your rice to the poor
    Click to Donate
    Click to feed Dogs & Cats


    Found any spamming-senders? Please report at: Spam Report

    2013年9月4日 上午 07:15
  • 依你的情境,你要把成員宣告成常數吧。


    強力監督SQL Injection問題!!

      • 小朱的技術隨手寫:http://www.dotblogs.com.tw/regionbbs/
      • 雲端學堂Facebook: http://www.facebook.com/studyazure

    2013年9月4日 上午 07:18
    版主
  • 依你的情境,你要把成員宣告成常數吧。


    強力監督SQL Injection問題!!

      • 小朱的技術隨手寫:http://www.dotblogs.com.tw/regionbbs/
      • 雲端學堂Facebook: http://www.facebook.com/studyazure

    我不是要常數,就像System.Drawing.Color既不是列舉型別也不是宣告為常數

    因為Interllisence上面明顯出現的Public Shared ReadOnly Property

    其他像是System.Drawing.Pen、System.Drawing.Brush也都有相同效果

    而System.Drawing.Color是結構

    System.Drawing.Pen、System.Drawing.Brush是類別

    2013年9月4日 上午 09:01
  • 参考  http://msdn.microsoft.com/en-us/library/8h84wky1.aspx

    不好意思忘了說

    我要在結構跟類別上做出這樣的效果,所以不是要列舉型別

    因為我要列舉的項目不是數值型別,所以無法使用列舉

    2013年9月4日 上午 09:12
  • 楼主可以看看源码,应该就知道是用TypeConverter了。

    If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer

    Help by clicking:
    Click here to donate your rice to the poor
    Click to Donate
    Click to feed Dogs & Cats


    Found any spamming-senders? Please report at: Spam Report

    2013年9月4日 上午 09:14
  • 楼主可以看看源码,应该就知道是用TypeConverter了。

    If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer

    Help by clicking:
    Click here to donate your rice to the poor
    Click to Donate
    Click to feed Dogs & Cats


    Found any spamming-senders? Please report at: Spam Report

    其實發文前我自己做了一個自訂結構StructA也做了StructAConverter

    不過沒有出現我想要的效果

    2013年9月4日 上午 11:01
  • 可以給出你的源代碼嗎?

    If you think one reply solves your problem, please mark it as An Answer, if you think someone's reply helps you, please mark it as a Proposed Answer

    Help by clicking:
    Click here to donate your rice to the poor
    Click to Donate
    Click to feed Dogs & Cats


    Found any spamming-senders? Please report at: Spam Report

    2013年9月5日 上午 02:08