Unit Structure
Represents a length measurement.
Assembly: System.Web (in System.Web.dll)
| Name | Description | |
|---|---|---|
![]() | Unit(Double) | Initializes a new instance of the Unit structure with the specified double precision floating point number. |
![]() | Unit(Double, UnitType) | Initializes a new instance of the Unit structure with the specified double precision floating point number and UnitType. |
![]() | Unit(Int32) | Initializes a new instance of the Unit structure with the specified 32-bit signed integer. |
![]() | Unit(String) | Initializes a new instance of the Unit structure with the specified length. |
![]() | Unit(String, CultureInfo) | Initializes a new instance of the Unit structure with the specified length and System.Globalization.CultureInfo. |
| Name | Description | |
|---|---|---|
![]() | Equals(Object) | Compares this Unit with the specified object.(Overrides ValueType.Equals(Object).) |
![]() | GetHashCode() | Returns the hash code for this instance.(Overrides ValueType.GetHashCode().) |
![]() | GetType() | |
![]() ![]() | Parse(String) | Converts the specified string to a Unit. |
![]() ![]() | Parse(String, CultureInfo) | Converts the specified string and System.Globalization.CultureInfo to a Unit. |
![]() ![]() | Percentage(Double) | Creates a Unit of type Percentage from the specified double-precision floating-point number. |
![]() ![]() | Pixel(Int32) | Creates a Unit of type Pixel from the specified 32-bit signed integer. |
![]() ![]() | Point(Int32) | Creates a Unit of type Point from the specified 32-bit signed integer. |
![]() | ToString() | This API supports the product infrastructure and is not intended to be used directly from your code. Converts a Unit to a System.String.(Overrides ValueType.ToString().) |
![]() | ToString(CultureInfo) | Converts a Unit to a string equivalent in the specified culture. |
![]() | ToString(IFormatProvider) | Converts a Unit to a string equivalent using the specified format provider. |
| Name | Description | |
|---|---|---|
![]() ![]() | Equality(Unit, Unit) | Compares two Unit objects to determine whether they are equal. |
![]() ![]() | Widening(Int32 to Unit) | Implicitly creates a Unit of type Pixel from the specified 32-bit unsigned integer. |
![]() ![]() | Inequality(Unit, Unit) | Compares two Unit objects to determine whether they are not equal. |
The Unit structure represents a length measurement that can be expressed in any HTML-compatible size unit. The UnitType enumeration lists the units of measurement that can be represented. The Unit is used by properties such as BorderWidth and Height to represent the length or width of the property. For example, you can set the BorderWidth property of a Web Server control to a Unit that represents five pixels.
Note |
|---|
The Unit class can represent values only between -32768 and 32767. |
Use the Value property to determine the length of the measurement. The unit of measurement is determined using the Type property. You can convert other data types to a Unit by using the Parse, Percentage, Pixel, and Point methods.
For a list of initial property values for an instance of Unit, see the Unit constructor.
The following code example demonstrates how to use a Style object to change the style properties of multiple controls at once. Each time one of the Style property values changes, each control must call its ApplyStyle method. Note that not all the controls support all the properties demonstrated. If a control does not support a particular property, the appearance of the control will not change when the property value is changed.
<%@ Page Language="VB" %> <%@ Import Namespace="System.Drawing" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> Private primaryStyle As New Style() Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) If Not Page.IsPostBack Then ' Add data to the borderColorList, ' backColorList, and foreColorList controls. Dim colors As New ListItemCollection() colors.Add(Color.Black.Name) colors.Add(Color.Blue.Name) colors.Add(Color.Green.Name) colors.Add(Color.Orange.Name) colors.Add(Color.Purple.Name) colors.Add(Color.Red.Name) colors.Add(Color.White.Name) colors.Add(Color.Yellow.Name) borderColorList.DataSource = colors borderColorList.DataBind() backColorList.DataSource = colors backColorList.DataBind() foreColorList.DataSource = colors foreColorList.DataBind() ' Add data to the borderStyleList control. Dim styles As New ListItemCollection() Dim styleType As Type = GetType(BorderStyle) Dim s As String For Each s In [Enum].GetNames(styleType) styles.Add(s) Next s borderStyleList.DataSource = styles borderStyleList.DataBind() ' Add data to the borderWidthList control. Dim widths As New ListItemCollection() Dim i As Integer For i = 0 To 10 widths.Add(i.ToString() & "px") Next i borderWidthList.DataSource = widths borderWidthList.DataBind() ' Add data to the fontNameList control. Dim names As New ListItemCollection() names.Add("Arial") names.Add("Courier") names.Add("Garamond") names.Add("Times New Roman") names.Add("Verdana") fontNameList.DataSource = names fontNameList.DataBind() ' Add data to the fontSizeList control. Dim fontSizes As New ListItemCollection() fontSizes.Add("Small") fontSizes.Add("Medium") fontSizes.Add("Large") fontSizes.Add("10pt") fontSizes.Add("14pt") fontSizes.Add("20pt") fontSizeList.DataSource = fontSizes fontSizeList.DataBind() ' Set primaryStyle as the style for each control. Label1.ApplyStyle(primaryStyle) ListBox1.ApplyStyle(primaryStyle) Button1.ApplyStyle(primaryStyle) Table1.ApplyStyle(primaryStyle) TextBox1.ApplyStyle(primaryStyle) End If End Sub Sub ChangeBorderColor(ByVal sender As Object, ByVal e As System.EventArgs) primaryStyle.BorderColor = _ Color.FromName(borderColorList.SelectedItem.Text) Label1.ApplyStyle(primaryStyle) ListBox1.ApplyStyle(primaryStyle) Button1.ApplyStyle(primaryStyle) Table1.ApplyStyle(primaryStyle) TextBox1.ApplyStyle(primaryStyle) End Sub Sub ChangeBackColor(ByVal sender As Object, ByVal e As System.EventArgs) primaryStyle.BackColor = _ Color.FromName(backColorList.SelectedItem.Text) Label1.ApplyStyle(primaryStyle) ListBox1.ApplyStyle(primaryStyle) Button1.ApplyStyle(primaryStyle) Table1.ApplyStyle(primaryStyle) TextBox1.ApplyStyle(primaryStyle) End Sub Sub ChangeForeColor(ByVal sender As Object, ByVal e As System.EventArgs) primaryStyle.ForeColor = _ Color.FromName(foreColorList.SelectedItem.Text) Label1.ApplyStyle(primaryStyle) ListBox1.ApplyStyle(primaryStyle) Button1.ApplyStyle(primaryStyle) Table1.ApplyStyle(primaryStyle) TextBox1.ApplyStyle(primaryStyle) End Sub Sub ChangeBorderStyle(ByVal sender As Object, ByVal e As System.EventArgs) primaryStyle.BorderStyle = _ CType([Enum].Parse(GetType(BorderStyle), _ borderStyleList.SelectedItem.Text), BorderStyle) Label1.ApplyStyle(primaryStyle) ListBox1.ApplyStyle(primaryStyle) Button1.ApplyStyle(primaryStyle) Table1.ApplyStyle(primaryStyle) TextBox1.ApplyStyle(primaryStyle) End Sub Sub ChangeBorderWidth(ByVal sender As Object, ByVal e As System.EventArgs) primaryStyle.BorderWidth = _ Unit.Parse(borderWidthList.SelectedItem.Text) Label1.ApplyStyle(primaryStyle) ListBox1.ApplyStyle(primaryStyle) Button1.ApplyStyle(primaryStyle) Table1.ApplyStyle(primaryStyle) TextBox1.ApplyStyle(primaryStyle) End Sub Sub ChangeFont(ByVal sender As Object, ByVal e As System.EventArgs) primaryStyle.Font.Name = _ fontNameList.SelectedItem.Text Label1.ApplyStyle(primaryStyle) ListBox1.ApplyStyle(primaryStyle) Button1.ApplyStyle(primaryStyle) Table1.ApplyStyle(primaryStyle) TextBox1.ApplyStyle(primaryStyle) End Sub Sub ChangeFontSize(ByVal sender As Object, ByVal e As System.EventArgs) primaryStyle.Font.Size = _ FontUnit.Parse(fontSizeList.SelectedItem.Text) Label1.ApplyStyle(primaryStyle) ListBox1.ApplyStyle(primaryStyle) Button1.ApplyStyle(primaryStyle) Table1.ApplyStyle(primaryStyle) TextBox1.ApplyStyle(primaryStyle) End Sub </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Applied Style Example</title> </head> <body> <form id="form1" runat="server"> <div> <table cellpadding="6" border="0"> <tr> <td rowspan="10" style="border:solid 1px Gray"> <p> <asp:label id="Label1" Text="Border Properties Example" Runat="server"> Label Styles </asp:label> </p> <p> <asp:button id="Button1" runat="server" Text="Button Styles"> </asp:button> </p> <p> <asp:listbox id="ListBox1" Runat="server"> <asp:ListItem Value="0" Text="List Item 0"> </asp:ListItem> <asp:ListItem Value="1" Text="List Item 1"> </asp:ListItem> <asp:ListItem Value="2" Text="List Item 2"> </asp:ListItem> </asp:listbox> </p> <p> <asp:textbox id="TextBox1" Text="TextBox Styles" Runat="server"> </asp:textbox> </p> <p> <asp:table id="Table1" Runat="server"> <asp:TableRow> <asp:TableCell Text="(0,0)"></asp:TableCell> <asp:TableCell Text="(0,1)"></asp:TableCell> </asp:TableRow> <asp:TableRow> <asp:TableCell Text="(1,0)"></asp:TableCell> <asp:TableCell Text="(1,1)"></asp:TableCell> </asp:TableRow> </asp:table> </p> </td> <td align="right"> <asp:Label ID="Label2" runat="server" AssociatedControlID="borderColorList" Text="Border Color:"> </asp:Label> </td> <td> <asp:dropdownlist id="borderColorList" Runat="server" AutoPostBack="True" OnSelectedIndexChanged="ChangeBorderColor"> </asp:dropdownlist> </td> </tr> <tr> <td align="right"> <asp:Label ID="Label3" Runat="server" AssociatedControlID="borderStyleList" Text="Border Style:"> </asp:Label> </td> <td> <asp:dropdownlist id="borderStyleList" Runat="server" AutoPostBack="True" OnSelectedIndexChanged="ChangeBorderStyle"> </asp:dropdownlist> </td> </tr> <tr> <td align="right"> <asp:Label ID="Label4" Runat="server" AssociatedControlID="borderWidthList" Text="Border Width"> </asp:Label> </td> <td> <asp:dropdownlist id="borderWidthList" Runat="server" AutoPostBack="True" OnSelectedIndexChanged="ChangeBorderWidth"> </asp:dropdownlist> </td> </tr> <tr> <td align="right"> <asp:Label ID="Label5" Runat="server" AssociatedControlID="backColorList" Text="Back Color:"> </asp:Label> </td> <td> <asp:dropdownlist id="backColorList" Runat="server" AutoPostBack="True" OnSelectedIndexChanged="ChangeBackColor"> </asp:dropdownlist> </td> </tr> <tr> <td align="right"> <asp:Label ID="Label6" Runat="server" AssociatedControlID="foreColorList" Text="Foreground Color:"> </asp:Label> </td> <td> <asp:dropdownlist id="foreColorList" Runat="server" AutoPostBack="True" OnSelectedIndexChanged="ChangeForeColor"> </asp:dropdownlist> </td> </tr> <tr> <td align="right"> <asp:Label ID="Label7" Runat="server" AssociatedControlID="fontNameList" Text="Font Name:"> </asp:Label> </td> <td> <asp:dropdownlist id="fontNameList" Runat="server" AutoPostBack="True" OnSelectedIndexChanged="ChangeFont"> </asp:dropdownlist> </td> </tr> <tr> <td align="right"> <asp:Label ID="Label8" Runat="server" AssociatedControlID="fontSizeList" Text="Font Size:"> </asp:Label> </td> <td> <asp:dropdownlist id="fontSizeList" Runat="server" AutoPostBack="True" OnSelectedIndexChanged="ChangeFontSize"> </asp:dropdownlist> </td> </tr> </table> </div> </form> </body> </html>
Available since 1.1
Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
.jpeg?cs-save-lang=1&cs-lang=vb)
.jpeg?cs-save-lang=1&cs-lang=vb)
.jpeg?cs-save-lang=1&cs-lang=vb)
.jpeg?cs-save-lang=1&cs-lang=vb)
.jpeg?cs-save-lang=1&cs-lang=vb)
.jpeg?cs-save-lang=1&cs-lang=vb)