Method FromString
FromString(string, CultureInfo?)
Converts a string representation of a coordinate value, including an optional unit, into a float object.
public static float FromString(string s, CultureInfo? cultureInfo)
Parameters
sstringThe string to parse. The string should be in the format "[value][unit]", where
[value]is a numeric value and[unit]is an optional unit specifier (e.g., "px", "in"). If no unit is specified, the value is interpreted as pixels. The special value "auto" is interpreted as NaN.cultureInfoCultureInfoThe CultureInfo used to interpret the numeric value in the string.
Returns
- float
A float object representing the parsed value. If the string specifies "auto", NaN is returned.
Remarks
This method is culture-sensitive for parsing the numeric value but uses a fixed, culture-invariant set of unit strings. Supported unit strings include "px" (pixels) and other predefined units. If the string does not end with a recognized unit, it is assumed to represent pixels.
Exceptions
- FormatException
Thrown if the string cannot be parsed into a valid coordinate value.