Font.SizeInPoints 属性

获取此 Font 的全身大小(以点为单位)。

**命名空间:**System.Drawing
**程序集:**System.Drawing(在 system.drawing.dll 中)

语法

声明
Public ReadOnly Property SizeInPoints As Single
用法
Dim instance As Font
Dim value As Single

value = instance.SizeInPoints
public float SizeInPoints { get; }
public:
property float SizeInPoints {
    float get ();
}
/** @property */
public float get_SizeInPoints ()
public function get SizeInPoints () : float

属性值

Font 的全身大小(以点为单位)。

示例

下面的代码示例演示如何使用 Font 构造函数以及 SizeSizeInPointsUnit 属性。此示例设计为与一个 Windows 窗体一起使用,该窗体包含一个名为 ComboBox1ComboBox,该组合框填有字符串“Bigger”和“Smaller”。将下面的代码粘贴到此窗体中,并且将 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 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

Font 类
Font 成员
System.Drawing 命名空间