<b>Edited by KraGiE: Added code tags to format the code.</b>
Here is how I did it (VB):
''' ----------------------------------------------------------------------------- ''' <summary> ''' Gets/Sets the BackColor of the grab handle. ''' </summary> ''' <value>System.Drawing.Color.</value> ''' <remarks> ''' </remarks> ''' <history> ''' [ESCHNEIDER0]6/21/2004Created ''' </history> ''' ----------------------------------------------------------------------------- <Description("Gets/Sets the BackColor of the grab handle"), Browsable(True), XmlIgnore(), DefaultValue("System.Drawing.Color.White")> _ Public Property BackgroundColor() As System.Drawing.Color Get Return m_BackColor End Get Set(ByVal value As System.Drawing.Color) m_BackColor = value End Set End Property
Private Function ShouldSerializeBackGroundColor() As Boolean Return True End Function
Private Sub ResetBackGroundColor() m_BackColor = System.Drawing.Color.White End Sub
''' ----------------------------------------------------------------------------- ''' <summary> ''' Defines a color format. ''' </summary> ''' <remarks> ''' </remarks> ''' <history> ''' [ESCHNEIDER0]8/6/2004Created ''' </history> ''' ----------------------------------------------------------------------------- Protected Enum ColorFormat ''' ----------------------------------------------------------------------------- ''' <summary> ''' NamedColor = 0 , Specifies that the color is a named color. ''' </summary> ''' <remarks> ''' </remarks> ''' <history> ''' [ESCHNEIDER0]8/6/2004Created ''' </history> ''' ----------------------------------------------------------------------------- NamedColor = 0
''' ----------------------------------------------------------------------------- ''' <summary> ''' ARGBColor = 1 , Specifies that the color is a RGB format. ''' </summary> ''' <remarks> ''' </remarks> ''' <history> ''' [ESCHNEIDER0]8/6/2004Created ''' </history> ''' ----------------------------------------------------------------------------- ArgbColor = 1 End Enum 'ColorFormat
''' ----------------------------------------------------------------------------- ''' <summary> ''' Used to serialize/deserialize the BackGroundColor. ''' </summary> ''' <value>String.</value> ''' <remarks> ''' </remarks> ''' <history> ''' [ESCHNEIDER0]8/9/2004Created ''' </history> ''' ----------------------------------------------------------------------------- <Browsable(False), XmlElement("BackGroundColor")> _ Public Property XmlColorType() As String Get Return Me.SerializeColor(BackgroundColor) End Get Set(ByVal Value As String) BackgroundColor = Me.DeserializeColor(Value) End Set End Property
''' ----------------------------------------------------------------------------- ''' <summary> ''' Function used to create a Serialize string for a Color object. ''' </summary> ''' <param name="color">Color.</param> ''' <returns>String.</returns> ''' <remarks> ''' </remarks> ''' <history> ''' [ESCHNEIDER0]8/29/2004Created ''' </history> ''' ----------------------------------------------------------------------------- Protected Shared Function SerializeColor(ByVal color As Color) As String If color.IsNamedColor Then Return String.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}:{1}", ColorFormat.NamedColor, color.Name) Else Return String.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}:{1}:{2}:{3}:{4}", ColorFormat.ArgbColor, color.A, color.R, color.G, color.B) End If
End Function 'SerializeColor
''' ----------------------------------------------------------------------------- ''' <summary> ''' Function used to convert a SerializeColor string into a Color object. ''' </summary> ''' <param name="colorValue">String.</param> ''' <returns>Color.</returns> ''' <remarks> ''' </remarks> ''' <history> ''' [ESCHNEIDER0]8/29/2004Created ''' </history> ''' ----------------------------------------------------------------------------- Protected Shared Function DeserializeColor(ByVal colorValue As String) As Color Dim a, r, g, b As Byte
Dim pieces As String() = colorValue.Split(New Char() {":"c})
Dim colorType As ColorFormat = CType([Enum].Parse(GetType(ColorFormat), pieces(0), True), ColorFormat)
Select Case colorType Case ColorFormat.NamedColor Return Color.FromName(pieces(1))
Case ColorFormat.ArgbColor a = Byte.Parse(pieces(1), System.Globalization.CultureInfo.InvariantCulture) r = Byte.Parse(pieces(2), System.Globalization.CultureInfo.InvariantCulture) g = Byte.Parse(pieces(3), System.Globalization.CultureInfo.InvariantCulture) b = Byte.Parse(pieces(4), System.Globalization.CultureInfo.InvariantCulture)
Return Color.FromArgb(a, r, g, b) End Select Return Color.Empty
End Function 'DeserializeColor
|