FontUnitとは? わかりやすく解説

Font.Unit プロパティ

この Font長さの単位取得します

名前空間: System.Drawing
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

Dim instance As Font
Dim value As GraphicsUnit

value = instance.Unit
public GraphicsUnit Unit { get; }
public:
property GraphicsUnit Unit {
    GraphicsUnit get ();
}
/** @property */
public GraphicsUnit get_Unit ()
public function get Unit
 () : GraphicsUnit

プロパティ
この Font長さの単位を表す GraphicsUnit。

使用例使用例

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
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

FontUnit コンストラクタ (String, CultureInfo)

文字列System.Globalization.CultureInfo オブジェクト指定して、FontUnit クラス新しインスタンス初期化します。

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public Sub New ( _
    value As String, _
    culture As CultureInfo _
)
public FontUnit (
    string value,
    CultureInfo culture
)
public:
FontUnit (
    String^ value, 
    CultureInfo^ culture
)
public FontUnit (
    String value, 
    CultureInfo culture
)
public function FontUnit (
    value : String, 
    culture : CultureInfo
)

パラメータ

value

フォント サイズ指定する文字列

culture

文字列比較使用する CultureInfo。

解説解説

FontUnit コンストラクタは、次の表に示す value文字列認識してFontUnit クラス新しインスタンス作成します

文字列

FontUnit

xx-small, xxsmall

XXSmall

x-small, xsmall

XSmall

x-large, xlarge

XLarge

xx-large, xxlarge

XXLarge

small

Small

smaller

Smaller

large

Large

larger

Larger

medium

Medium

どの場合でも、Type プロパティの値は NotSet になります文字列比較では、大文字と小文字区別されません。

value のその他すべての値については、valueフォント サイズとして処理しType プロパティPoint設定することによって、FontUnit クラス新しインスタンス作成されます。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
FontUnit 構造体
FontUnit メンバ
System.Web.UI.WebControls 名前空間
FontUnit

FontUnit コンストラクタ (Double, UnitType)

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

指定したフォント サイズUnitType 値を使用して、FontUnit クラス新しインスタンス初期化します。

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public Sub New ( _
    value As Double, _
    type As UnitType _
)
public FontUnit (
    double value,
    UnitType type
)
public:
FontUnit (
    double value, 
    UnitType type
)
public FontUnit (
    double value, 
    UnitType type
)
public function FontUnit (
    value : double, 
    type : UnitType
)

パラメータ

value

フォント サイズ指定する Double

type

そのサイズ単位指定する UnitType。

例外例外
例外種類条件

ArgumentOutOfRangeException

value が有効範囲外です。

解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
FontUnit 構造体
FontUnit メンバ
System.Web.UI.WebControls 名前空間
FontSize 列挙
Type
Unit
Value
Type
AsUnit

FontUnit コンストラクタ (FontSize)

FontSize指定して、FontUnit クラス新しインスタンス初期化します。

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public Sub New ( _
    type As FontSize _
)
Dim type As FontSize

Dim instance As New FontUnit(type)
public FontUnit (
    FontSize type
)
public:
FontUnit (
    FontSize type
)
public FontUnit (
    FontSize type
)
public function FontUnit (
    type : FontSize
)

パラメータ

type

FontSize 値の 1 つ

例外例外
例外種類条件

ArgumentException

指定したフォント サイズFontSize 値ではありません。

解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
FontUnit 構造体
FontUnit メンバ
System.Web.UI.WebControls 名前空間
FontSize 列挙
Type
Unit
Value

FontUnit コンストラクタ (Double)

メモ : このコンストラクタは、.NET Framework version 2.0新しく追加されたものです。

フォント サイズポイント指定して、FontUnit クラス新しインスタンス初期化します。

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

例外例外
例外種類条件

ArgumentOutOfRangeException

value が有効範囲外です。

解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
FontUnit 構造体
FontUnit メンバ
System.Web.UI.WebControls 名前空間
FontSize 列挙
Type
Unit
Value
AsUnit

FontUnit コンストラクタ (Unit)

Unit指定して、FontUnit クラス新しインスタンス初期化します。

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
FontUnit 構造体
FontUnit メンバ
System.Web.UI.WebControls 名前空間
FontSize 列挙
Type
Unit

FontUnit コンストラクタ (String)


FontUnit コンストラクタ (Int32)

指定したフォント サイズ使用して、FontUnit クラス新しインスタンス初期化します。

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
FontUnit 構造体
FontUnit メンバ
System.Web.UI.WebControls 名前空間
FontSize 列挙
Type
Unit
Value

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 構造体
System.Web.UI.WebControls 名前空間

FontUnit プロパティ


パブリック プロパティパブリック プロパティ

参照参照

関連項目

FontUnit 構造体
System.Web.UI.WebControls 名前空間

FontUnit メソッド


パブリック メソッドパブリック メソッド

プロテクト メソッドプロテクト メソッド
参照参照

関連項目

FontUnit 構造体
System.Web.UI.WebControls 名前空間

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 構造体
System.Web.UI.WebControls 名前空間

FontUnit 構造体

フォントサイズ表します

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)
構文構文

<SerializableAttribute> _
Public Structure FontUnit
[SerializableAttribute] 
public struct FontUnit
[SerializableAttribute] 
public value class FontUnit
/** @attribute SerializableAttribute() */ 
public final class FontUnit extends ValueType
JScript では、構造体使用できますが、新規に宣言することはできません。
解説解説
使用例使用例

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>
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
FontUnit メンバ
System.Web.UI.WebControls 名前空間



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「FontUnit」の関連用語

FontUnitのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



FontUnitのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS