ExtensionMethod.NET Home of 841 C#, Visual Basic, F# and Javascript extension methods

Color.ToHtmlColor

Converts a Color object to a string suitable for including in HTML or CSS.

Source

namespace Foo

open System
open System.Drawing

[<AutoOpen>]
module FsExtensions =

    let private hexColor = sprintf "#%02x%02x%02x"

    type Color with
        /// Converts the color to an html #RRGGBB string, or a name.
        member this.ToHtmlColor() =
            if this.IsNamedColor then
this.Name
            else
hexColor this.R this.G this.B

Example

let htmlColor = someColor.ToHtmlColor()

Author: Joel Mueller

Submitted on: 29 okt 2010

Language: F#

Type: System.Drawing.Color

Views: 3504