Font.Unit プロパティ
アセンブリ: System.Drawing (system.drawing.dll 内)


Font コンストラクタと Size、SizeInPoints、および Unit の各プロパティを使用する方法を次のコード例に示します。この例は、ComboBox1 という名前の ComboBox に "Bigger" と "Smaller" という文字列が設定された Windows フォームでの使用を意図してデザインされています。そして、次のコードをそのフォームに貼り付け、ComboBox1_SelectedIndexChanged メソッドに、ComboBox コントロールの SelectedIndexChanged イベントを関連付けます。
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged ' Cast the sender object back to a ComboBox. Dim ComboBox1 As ComboBox = CType(sender, ComboBox) ' Retrieve the selected item. Dim selectedString As String = CType(ComboBox1.SelectedItem, String) ' Convert it to lowercase. selectedString = selectedString.ToLower() ' Declare the current size. Dim currentSize As Single ' Switch on the selected item. Select Case selectedString ' If Bigger is selected, get the current size from the ' Size property and increase it. Reset the font to the ' new size, using the current unit. Case "bigger" currentSize = Label1.Font.Size currentSize += 2.0F Label1.Font = New Font(Label1.Font.Name, currentSize, _ Label1.Font.Style, Label1.Font.Unit) ' If Smaller is selected, get the current size, in points , ' and decrease it by 1. Reset the font with the new size ' in points. Case "smaller" currentSize = Label1.Font.SizeInPoints currentSize -= 1 Label1.Font = New Font(Label1.Font.Name, currentSize, _ Label1.Font.Style) End Select End Sub
private void ComboBox1_SelectedIndexChanged(System.Object sender, System.EventArgs e) { // Cast the sender object back to a ComboBox. ComboBox ComboBox1 = (ComboBox) sender; // Retrieve the selected item. string selectedString = (string) ComboBox1.SelectedItem; // Convert it to lowercase. selectedString = selectedString.ToLower(); // Declare the current size. float currentSize; // Switch on the selected item. switch(selectedString) { // If Bigger is selected, get the current size from the // Size property and increase it. Reset the font to the // new size, using the current unit. case "bigger": currentSize = Label1.Font.Size; currentSize += 2.0F; Label1.Font = new Font(Label1.Font.Name, currentSize, Label1.Font.Style, Label1.Font.Unit); // If Smaller is selected, get the current size, in points , // and decrease it by 1. Reset the font with the new size // in points. break; case "smaller": currentSize = Label1.Font.SizeInPoints; currentSize -= 1; Label1.Font = new Font(Label1.Font.Name, currentSize, Label1.Font.Style); break; } }
private: void ComboBox1_SelectedIndexChanged(System::Object^ sender , System::EventArgs^ e) { // Cast the sender object back to a ComboBox. ComboBox^ ComboBox1 = (ComboBox^) sender; // Retrieve the selected item. String^ selectedString = (String^) ComboBox1->SelectedItem; // Convert it to lowercase. selectedString = selectedString->ToLower(); // Declare the current size. float currentSize; // If Bigger is selected, get the current size from the // Size property and increase it. Reset the font to the // new size, using the current unit. if (selectedString == "bigger") { currentSize = Label1->Font->Size; currentSize += 2.0F; Label1->Font =gcnew System::Drawing::Font(Label1->Font->Name, currentSize, Label1->Font->Style, Label1->Font->Unit); } // If Smaller is selected, get the current size, in // points, and decrease it by 2. Reset the font with // the new size in points. if (selectedString == "smaller") { currentSize = Label1->Font->Size; currentSize -= 2.0F; Label1->Font = gcnew System::Drawing::Font(Label1->Font->Name, currentSize, Label1->Font->Style); } }
private void comboBox1_SelectedIndexChanged(Object sender, System.EventArgs e) { // Cast the sender object back to a ComboBox. ComboBox comboBox1 = (ComboBox)sender; // Retrieve the selected item. String selectedString = (String)comboBox1.get_SelectedItem(); // Convert it to lowercase. selectedString = selectedString.ToLower(); // Declare the current size. float currentSize; // Switch on the selected item. // If Bigger is selected, get the current size from the // Size property and increase it. Reset the font to the // new size, using the current unit. if (selectedString.Equals("bigger")) { currentSize = label1.get_Font().get_Size(); currentSize += 2; label1.set_Font(new Font(label1.get_Font().get_Name(), currentSize, label1.get_Font().get_Style(), label1.get_Font().get_Unit())); } else { // If Smaller is selected, get the current size, in points, // and decrease it by 1. Reset the font with the new size // in points. if (selectedString.Equals("smaller")) { currentSize = label1.get_Font().get_SizeInPoints(); currentSize -= 1; label1.set_Font(new Font(label1.get_Font().get_Name(), currentSize, label1.get_Font().get_Style())); } } } //comboBox1_SelectedIndexChanged

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


FontUnit コンストラクタ (String, CultureInfo)
アセンブリ: System.Web (system.web.dll 内)


FontUnit コンストラクタは、次の表に示す value の文字列を認識して、FontUnit クラスの新しいインスタンスを作成します。
文字列値 | FontUnit |
---|---|
xx-small, xxsmall | XXSmall |
x-small, xsmall | XSmall |
xx-large, xxlarge | XXLarge |
larger | Larger |
どの場合でも、Type プロパティの値は NotSet になります。文字列比較では、大文字と小文字は区別されません。
value のその他すべての値については、value をフォント サイズとして処理し、Type プロパティを Point に設定することによって、FontUnit クラスの新しいインスタンスが作成されます。

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


FontUnit コンストラクタ (Double, UnitType)
アセンブリ: System.Web (system.web.dll 内)



FontUnit コンストラクタを使用して、指定したフォント サイズと単位 (ポイント、ピクセルなど) で FontUnit クラスのインスタンスを作成し、初期化します。
FontUnit オブジェクトの初期プロパティ値を次の表に示します。

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


FontUnit コンストラクタ (FontSize)
アセンブリ: System.Web (system.web.dll 内)



このコンストラクタは、指定した FontSize オブジェクトを使用して FontUnit クラスの新しいインスタンスを作成し、初期化するために使用します。
type パラメータに値 FontSize.AsUnit が含まれている場合における、FontUnit のインスタンスの初期プロパティ値を次の表に示します。
type パラメータに他の FontSize 値が含まれている場合における、FontUnit のインスタンスの初期プロパティ値を次の表に示します。

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


FontUnit コンストラクタ (Double)
アセンブリ: System.Web (system.web.dll 内)



FontUnit コンストラクタを使用して、指定したフォント サイズで FontUnit クラスのインスタンスを作成し、初期化します。作成される FontUnit オブジェクトの初期プロパティ値を次の表に示します。

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


FontUnit コンストラクタ (Unit)
アセンブリ: System.Web (system.web.dll 内)


このコンストラクタを使用して、指定した Unit で FontUnit クラスの新しいインスタンスを作成し、初期化します。
value パラメータに渡された Unit の IsEmpty プロパティが true の場合における、FontUnit のインスタンスの初期プロパティ値を次の表に示します。
value パラメータに渡された Unit の IsEmpty プロパティが false の場合における、FontUnit のインスタンスの初期プロパティ値を次の表に示します。

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


FontUnit コンストラクタ (String)
アセンブリ: System.Web (system.web.dll 内)



Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


FontUnit コンストラクタ (Int32)
アセンブリ: System.Web (system.web.dll 内)



Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


FontUnit コンストラクタ

名前 | 説明 |
---|---|
FontUnit (Double) | フォント サイズをポイントで指定して、FontUnit クラスの新しいインスタンスを初期化します。 |
FontUnit (FontSize) | FontSize を指定して、FontUnit クラスの新しいインスタンスを初期化します。 |
FontUnit (Int32) | 指定したフォント サイズを使用して、FontUnit クラスの新しいインスタンスを初期化します。 |
FontUnit (String) | 文字列を指定して、FontUnit クラスの新しいインスタンスを初期化します。 |
FontUnit (Unit) | Unit を指定して、FontUnit クラスの新しいインスタンスを初期化します。 |
FontUnit (Double, UnitType) | 指定したフォント サイズと UnitType 値を使用して、FontUnit クラスの新しいインスタンスを初期化します。 |
FontUnit (String, CultureInfo) | 文字列と System.Globalization.CultureInfo オブジェクトを指定して、FontUnit クラスの新しいインスタンスを初期化します。 |

FontUnit フィールド

名前 | 説明 | |
---|---|---|
![]() | Empty | 空の FontUnit オブジェクトを表します。 |
![]() | Large | Type プロパティが FontSize.Large に設定された FontUnit オブジェクトを表します。 |
![]() | Larger | Type プロパティが FontSize.Larger に設定された FontUnit オブジェクトを表します。 |
![]() | Medium | Type プロパティが FontSize.Medium に設定された FontUnit オブジェクトを表します。 |
![]() | Small | Type プロパティが FontSize.Small に設定された FontUnit オブジェクトを表します。 |
![]() | Smaller | Type プロパティが FontSize.Smaller に設定された FontUnit オブジェクトを表します。 |
![]() | XLarge | Type プロパティが FontSize.XLarge に設定された FontUnit オブジェクトを表します。 |
![]() | XSmall | Type プロパティが FontSize.XSmall に設定された FontUnit オブジェクトを表します。 |
![]() | XXLarge | Type プロパティが FontSize.XXLarge に設定された FontUnit オブジェクトを表します。 |
![]() | XXSmall | Type プロパティが FontSize.XXSmall に設定された FontUnit オブジェクトを表します。 |

FontUnit プロパティ

名前 | 説明 | |
---|---|---|
![]() | IsEmpty | フォント サイズが設定されているかどうかを示す値を取得します。 |
![]() | Type | フォント サイズを表す FontSize 列挙値を取得します。 |
![]() | Unit | フォント サイズを表す Unit を取得します。 |

FontUnit メソッド

名前 | 説明 | |
---|---|---|
![]() | Equals | オーバーロードされます。 オーバーライドされます。 指定したオブジェクトが Equals メソッドの呼び出し元の FontUnit クラスのインスタンスと等価かどうかを確認します。 |
![]() | GetHashCode | オーバーライドされます。 このインスタンスのハッシュ コードを返します。 |
![]() | GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) |
![]() | op_Equality | 2 つの FontUnit オブジェクトが等しいかどうかを比較します。 |
![]() | op_Implicit | 整数値から System.Drawing.Point 型の FontUnit を暗黙的に作成します。 |
![]() | op_Inequality | 2 つの FontUnit オブジェクトが等しくないかどうかを比較します。 |
![]() | Parse | オーバーロードされます。 指定した文字列をそれと等価の FontUnit に変換します。 |
![]() | Point | 整数値から System.Drawing.Point 型の FontUnit を作成します。 |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
![]() | ToString | オーバーロードされます。 オーバーライドされます。 FontUnit オブジェクトを文字列形式に変換します。 |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |

FontUnit メンバ
FontUnit データ型で公開されるメンバを以下の表に示します。


名前 | 説明 | |
---|---|---|
![]() | Empty | 空の FontUnit オブジェクトを表します。 |
![]() | Large | Type プロパティが FontSize.Large に設定された FontUnit オブジェクトを表します。 |
![]() | Larger | Type プロパティが FontSize.Larger に設定された FontUnit オブジェクトを表します。 |
![]() | Medium | Type プロパティが FontSize.Medium に設定された FontUnit オブジェクトを表します。 |
![]() | Small | Type プロパティが FontSize.Small に設定された FontUnit オブジェクトを表します。 |
![]() | Smaller | Type プロパティが FontSize.Smaller に設定された FontUnit オブジェクトを表します。 |
![]() | XLarge | Type プロパティが FontSize.XLarge に設定された FontUnit オブジェクトを表します。 |
![]() | XSmall | Type プロパティが FontSize.XSmall に設定された FontUnit オブジェクトを表します。 |
![]() | XXLarge | Type プロパティが FontSize.XXLarge に設定された FontUnit オブジェクトを表します。 |
![]() | XXSmall | Type プロパティが FontSize.XXSmall に設定された FontUnit オブジェクトを表します。 |

名前 | 説明 | |
---|---|---|
![]() | IsEmpty | フォント サイズが設定されているかどうかを示す値を取得します。 |
![]() | Type | フォント サイズを表す FontSize 列挙値を取得します。 |
![]() | Unit | フォント サイズを表す Unit を取得します。 |

名前 | 説明 | |
---|---|---|
![]() | Equals | オーバーロードされます。 オーバーライドされます。 指定したオブジェクトが Equals メソッドの呼び出し元の FontUnit クラスのインスタンスと等価かどうかを確認します。 |
![]() | GetHashCode | オーバーライドされます。 このインスタンスのハッシュ コードを返します。 |
![]() | GetType | 現在のインスタンスの Type を取得します。 (Object から継承されます。) |
![]() | op_Equality | 2 つの FontUnit オブジェクトが等しいかどうかを比較します。 |
![]() | op_Implicit | 整数値から System.Drawing.Point 型の FontUnit を暗黙的に作成します。 |
![]() | op_Inequality | 2 つの FontUnit オブジェクトが等しくないかどうかを比較します。 |
![]() | Parse | オーバーロードされます。 指定した文字列をそれと等価の FontUnit に変換します。 |
![]() | Point | 整数値から System.Drawing.Point 型の FontUnit を作成します。 |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) |
![]() | ToString | オーバーロードされます。 オーバーライドされます。 FontUnit オブジェクトを文字列形式に変換します。 |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |

FontUnit 構造体
アセンブリ: System.Web (system.web.dll 内)



Style オブジェクトを使用して、複数のコントロールのスタイル プロパティを一度に変更するコード例を次に示します。Style プロパティの 1 つの値が変更されるたびに、各コントロールでその ApplyStyle メソッドを呼び出す必要があります。この例に含まれているコントロールの中には、説明するプロパティの一部がサポートされないものがあります。特定のプロパティがコントロールでサポートされない場合、プロパティ値を変更してもコントロールの外観は変更されません。
<%@ Page language="VB" AutoEventWireup="true" %> <%@ Import Namespace="System.Drawing" %> <%@ Import Namespace="System.Data" %> <html> <head> <script runat="server"> Private Dim primaryStyle As New Style() Sub Page_Load(sender As Object, 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("Time 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(sender As Object, 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(sender As Object, 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(sender As Object, 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(sender As Object, 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(sender As Object, 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(sender As Object, 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(sender As Object, 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> </head> <body> <form id="Form1" runat="server"> <table cellPadding="6" border="0"> <tr> <td> <asp:label id="Label1" Text="Border Properties Example" Runat="server"> <center><br>Label Styles</center> </asp:label> </td> <td> <asp:button id="Button1" runat="server" Text="Button Styles"> </asp:button> </td> <td> <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> </td> <td> <asp:textbox id="TextBox1" Text="TextBox Styles" Runat="server"> </asp:textbox> </td> <td> <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> </td> </tr> <tr> <td> <asp:Label Runat="server" Text="Border Color:"> </asp:Label> <asp:dropdownlist id="borderColorList" Runat="server" AutoPostBack="True" OnSelectedIndexChanged="ChangeBorderColor"> </asp:dropdownlist> <br> <asp:Label Runat="server" Text="Border Style:"> </asp:Label> <asp:dropdownlist id="borderStyleList" Runat="server" AutoPostBack="True" OnSelectedIndexChanged="ChangeBorderStyle"> </asp:dropdownlist> <br> <asp:Label Runat="server" Text="Border Width"> </asp:Label> <asp:dropdownlist id="borderWidthList" Runat="server" AutoPostBack="True" OnSelectedIndexChanged="ChangeBorderWidth"> </asp:dropdownlist> </td> <td> <asp:Label Runat="server" Text="Back Color:"> </asp:Label> <asp:dropdownlist id="backColorList" Runat="server" AutoPostBack="True" OnSelectedIndexChanged="ChangeBackColor"> </asp:dropdownlist> <br> <asp:Label Runat="server" Text="Foreground Color:"> </asp:Label> <asp:dropdownlist id="foreColorList" Runat="server" AutoPostBack="True" OnSelectedIndexChanged="ChangeForeColor"> </asp:dropdownlist> </td> <td> <asp:Label Runat="server" Text="Font Name:"> </asp:Label> <asp:dropdownlist id="fontNameList" Runat="server" AutoPostBack="True" OnSelectedIndexChanged="ChangeFont"> </asp:dropdownlist> <br> <asp:Label Runat="server" Text="Font Size:"> </asp:Label> <asp:dropdownlist id="fontSizeList" Runat="server" AutoPostBack="True" OnSelectedIndexChanged="ChangeFontSize"> </asp:dropdownlist> </td> </tr> </table> </form> </body> </html>
<%@ Page language="C#" AutoEventWireup="true" %> <%@ Import Namespace="System.Drawing" %> <%@ Import Namespace="System.Data" %> <html> <head> <script runat="server"> private Style primaryStyle = new Style(); void Page_Load(object sender, System.EventArgs e) { if (!Page.IsPostBack) { // Add data to the borderColorList, // backColorList, and foreColorList controls. ListItemCollection colors = 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. ListItemCollection styles = new ListItemCollection(); Type styleType = typeof(BorderStyle); foreach (string s in Enum.GetNames(styleType)) { styles.Add(s); } borderStyleList.DataSource = styles; borderStyleList.DataBind(); // Add data to the borderWidthList control. ListItemCollection widths = new ListItemCollection(); for (int i = 0; i < 11; i++) { widths.Add(i.ToString() + "px"); } borderWidthList.DataSource = widths; borderWidthList.DataBind(); // Add data to the fontNameList control. ListItemCollection names = new ListItemCollection(); names.Add("Arial"); names.Add("Courier"); names.Add("Garamond"); names.Add("Time New Roman"); names.Add("Verdana"); fontNameList.DataSource = names; fontNameList.DataBind(); // Add data to the fontSizeList control. ListItemCollection fontSizes = 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); } } void ChangeBorderColor(object sender, System.EventArgs e) { primaryStyle.BorderColor = Color.FromName(borderColorList.SelectedItem.Text); Label1.ApplyStyle(primaryStyle); ListBox1.ApplyStyle(primaryStyle); Button1.ApplyStyle(primaryStyle); Table1.ApplyStyle(primaryStyle); TextBox1.ApplyStyle(primaryStyle); } void ChangeBackColor(object sender, System.EventArgs e) { primaryStyle.BackColor = Color.FromName(backColorList.SelectedItem.Text); Label1.ApplyStyle(primaryStyle); ListBox1.ApplyStyle(primaryStyle); Button1.ApplyStyle(primaryStyle); Table1.ApplyStyle(primaryStyle); TextBox1.ApplyStyle(primaryStyle); } void ChangeForeColor(object sender, System.EventArgs e) { primaryStyle.ForeColor = Color.FromName(foreColorList.SelectedItem.Text); Label1.ApplyStyle(primaryStyle); ListBox1.ApplyStyle(primaryStyle); Button1.ApplyStyle(primaryStyle); Table1.ApplyStyle(primaryStyle); TextBox1.ApplyStyle(primaryStyle); } void ChangeBorderStyle(object sender, System.EventArgs e) { primaryStyle.BorderStyle = (BorderStyle)Enum.Parse(typeof(BorderStyle), borderStyleList.SelectedItem.Text); Label1.ApplyStyle(primaryStyle); ListBox1.ApplyStyle(primaryStyle); Button1.ApplyStyle(primaryStyle); Table1.ApplyStyle(primaryStyle); TextBox1.ApplyStyle(primaryStyle); } void ChangeBorderWidth(object sender, System.EventArgs e) { primaryStyle.BorderWidth = Unit.Parse(borderWidthList.SelectedItem.Text); Label1.ApplyStyle(primaryStyle); ListBox1.ApplyStyle(primaryStyle); Button1.ApplyStyle(primaryStyle); Table1.ApplyStyle(primaryStyle); TextBox1.ApplyStyle(primaryStyle); } void ChangeFont(object sender, System.EventArgs e) { primaryStyle.Font.Name = fontNameList.SelectedItem.Text; Label1.ApplyStyle(primaryStyle); ListBox1.ApplyStyle(primaryStyle); Button1.ApplyStyle(primaryStyle); Table1.ApplyStyle(primaryStyle); TextBox1.ApplyStyle(primaryStyle); } void ChangeFontSize(object sender, System.EventArgs e) { primaryStyle.Font.Size = FontUnit.Parse(fontSizeList.SelectedItem.Text); Label1.ApplyStyle(primaryStyle); ListBox1.ApplyStyle(primaryStyle); Button1.ApplyStyle(primaryStyle); Table1.ApplyStyle(primaryStyle); TextBox1.ApplyStyle(primaryStyle); } </script> </head> <body> <form id="Form1" runat="server"> <table cellPadding="6" border="0"> <tr> <td> <asp:label id="Label1" Text="Border Properties Example" Runat="server"> <center><br>Label Styles</center> </asp:label> </td> <td> <asp:button id="Button1" runat="server" Text="Button Styles"> </asp:button> </td> <td> <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> </td> <td> <asp:textbox id="TextBox1" Text="TextBox Styles" Runat="server"> </asp:textbox> </td> <td> <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> </td> </tr> <tr> <td> <asp:Label Runat="server" Text="Border Color:"> </asp:Label> <asp:dropdownlist id="borderColorList" Runat="server" AutoPostBack="True" OnSelectedIndexChanged="ChangeBorderColor"> </asp:dropdownlist> <br> <asp:Label Runat="server" Text="Border Style:"> </asp:Label> <asp:dropdownlist id="borderStyleList" Runat="server" AutoPostBack="True" OnSelectedIndexChanged="ChangeBorderStyle"> </asp:dropdownlist> <br> <asp:Label Runat="server" Text="Border Width"> </asp:Label> <asp:dropdownlist id="borderWidthList" Runat="server" AutoPostBack="True" OnSelectedIndexChanged="ChangeBorderWidth"> </asp:dropdownlist> </td> <td> <asp:Label Runat="server" Text="Back Color:"> </asp:Label> <asp:dropdownlist id="backColorList" Runat="server" AutoPostBack="True" OnSelectedIndexChanged="ChangeBackColor"> </asp:dropdownlist> <br> <asp:Label Runat="server" Text="Foreground Color:"> </asp:Label> <asp:dropdownlist id="foreColorList" Runat="server" AutoPostBack="True" OnSelectedIndexChanged="ChangeForeColor"> </asp:dropdownlist> </td> <td> <asp:Label Runat="server" Text="Font Name:"> </asp:Label> <asp:dropdownlist id="fontNameList" Runat="server" AutoPostBack="True" OnSelectedIndexChanged="ChangeFont"> </asp:dropdownlist> <br> <asp:Label Runat="server" Text="Font Size:"> </asp:Label> <asp:dropdownlist id="fontSizeList" Runat="server" AutoPostBack="True" OnSelectedIndexChanged="ChangeFontSize"> </asp:dropdownlist> </td> </tr> </table> </form> </body> </html>


Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- FontUnitのページへのリンク