Font.Unit Özellik

Tanım

Bu Fontiçin ölçü birimini alır.

C#
public System.Drawing.GraphicsUnit Unit { get; }
C#
[System.ComponentModel.TypeConverter(typeof(System.Drawing.FontConverter+FontUnitConverter))]
public System.Drawing.GraphicsUnit Unit { get; }

Özellik Değeri

GraphicsUnit Bu Fontiçin ölçü birimini temsil eden bir .

Öznitelikler

Örnekler

Aşağıdaki kod örneği oluşturucunun Font ve Size, SizeInPointsve Unit özelliklerinin nasıl kullanılacağını gösterir. Bu örnek, "Daha Büyük" ve "Daha Küçük" dizeleriyle doldurulmuş bir adlandırılmış ComboBox1 içeren bir ComboBox Windows Formu ile kullanılmak üzere tasarlanmıştır. Aşağıdaki kodu forma yapıştırın ve yöntemini denetimin SelectedIndexChanged olayıyla ilişkilendirin.ComboBox1_SelectedIndexChangedComboBox

C#
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;
    }
}

Şunlara uygulanır

Ürün Sürümler
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9