Control.FontSize 屬性

定義

取得或設定字型大小。

C#
[System.ComponentModel.Bindable(true)]
[System.ComponentModel.TypeConverter(typeof(System.Windows.FontSizeConverter))]
[System.Windows.Localizability(System.Windows.LocalizationCategory.None)]
public double FontSize { get; set; }

屬性值

Control 中的文字大小。 預設為 MessageFontSize。 字型大小必須為正數。

屬性

範例

下列範例示範如何設定控制項的字型大小屬性。

XAML
<Button Name="btn3" FontSize="10.0" 
        Click="ChangeFontSize">
  FontSize
</Button>
C#
void ChangeFontSize(object sender, RoutedEventArgs e)
{
    fsize = btn3.FontSize;
    if (fsize == 16.0)
    {
        btn3.FontSize = 10.0;
        btn3.Content = "FontSize";
    }
    else
    {
        btn3.FontSize = 16.0;
        btn3.Content = "Control font size changes from 10 to 16.";
    }
}

備註

此屬性只會影響範本使用 FontSize 屬性做為參數的控制項。 在其他控制項上,此屬性不會有任何影響。

相依性屬性資訊

識別碼欄位 FontSizeProperty
設定為 的中繼資料屬性 true AffectsMeasure, AffectsRender, Inherits

XAML Attribute Usage

<object FontSize="double"/>  
- or -  
<object FontSize ="qualifiedDouble"/>  

XAML 值

double
Double

值的字串表示 Double 。 這會解譯為裝置獨立單位, (1/96 英吋) 測量。 字串不需要明確包含小數點。 例如, 的值 1 是可接受的。

[屬性值] 區段中提及的相同 Double 範圍限制適用于這裡。

qualifiedDouble
如先前所述的 雙精度 浮點數,後面接著下列其中一個單位宣告字串: px 、、 incmpt

px (預設) 是裝置獨立單位 (每單位 1/96 英吋)

in 為英吋;1in==96px

cm 為公分;1cm== (96/2.54) px

pt 為點;1pt== (96/72) px

注意 在許多情況下,雙精度浮點數可能會設定為 「Auto」,但如果 Control.FontSize 設定為 「Auto」,則不會轉譯 。

適用於

產品 版本
.NET Framework 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