Class
HtmlStyle

Represents a single HtmlStyle. This object can be used to help probe and do validation against Html styles. Has functionality to convert unit styles to int values and color styles to System.Drawing.Color.

Definition

Namespace:ArtOfTest.WebAii.Controls.HtmlControls

Assembly:ArtOfTest.WebAii.dll

Syntax:

cs-api-definition
public class HtmlStyle

Inheritance: objectHtmlStyle

Constructors

HtmlStyle(string, string)

Create a new HtmlStyle object.

Declaration

cs-api-definition
public HtmlStyle(string name, string value)

Parameters

name

string

The name of the style.

value

string

The raw value of this style.

Properties

Name

Gets the style name.

Declaration

cs-api-definition
public string Name { get; }

Property Value

string

Value

Gets the style value.

Declaration

cs-api-definition
public string Value { get; }

Property Value

string

Methods

IsColor()

Whether the value of this style is a color value or not.

Declaration

cs-api-definition
public bool IsColor()

Returns

bool

True if style value is a color

IsInt()

Whether the value of this style is an integer value or not.

Declaration

cs-api-definition
public bool IsInt()

Returns

bool

True if a value is an integer value.

IsSameColor(Color, Color)

Performs a simple color compare that only compares red/green/blue colors. Does not compare known color names or alpha blending.

Declaration

cs-api-definition
public static bool IsSameColor(Color colorA, Color colorB)

Parameters

colorA

Color

Color A to compare

colorB

Color

Color B to compare

Returns

bool

True/False whether the two colors have identical RGB colors.

Remarks

Use this to compare colors instead of System.Color.Equals() to allow your compares to work across browsers. For example, IE returns colors as named colors (yellow, red ..etc) for computed styles where Mozilla always returns (rgb(x,y,z)). Using the HtmlStyle.ToColor and IsSameColor() can help abstract these differences and allow you to perform the compare across browsers.

ToColor()

Attempts to parse the style value as a color and return a System.Drawing.Color object that corresponds to the color style value.

Declaration

cs-api-definition
public Color ToColor()

Returns

Color

The System.Drawing.Color object or Color.Empty if unable to parse the color.

ToHtmlColor(Color)

Translates a System.Drawing.Color to an Html color string.

Declaration

cs-api-definition
public static string ToHtmlColor(Color color)

Parameters

color

Color

The System.Drawing.Color.

Returns

string

The html color string.

ToInt()

Strips any style value from units (i.e. px/pt..etc) and returns the integer value.

Declaration

cs-api-definition
public int ToInt()

Returns

int

The integer value. If the unit has no integer value or is empty will return -1.