Control.FontSize Control.FontSize Control.FontSize Control.FontSize Property


取得或設定字型大小。Gets or sets the font size.

 property double FontSize { double get(); void set(double value); };
public double FontSize { get; set; }
member this.FontSize : double with get, set
Public Property FontSize As Double


Control 中的文字大小。The size of the text in the Control. 預設為 MessageFontSizeThe default is MessageFontSize. 字型大小必須為正數。The font size must be a positive number.


下列範例示範如何設定控制項的字型的大小屬性。The following example shows how to set the font size property of a control.

<Button Name="btn3" FontSize="10.0" 
void ChangeFontSize(object sender, RoutedEventArgs e)
    fsize = btn3.FontSize;
    if (fsize == 16.0)
        btn3.FontSize = 10.0;
        btn3.Content = "FontSize";
        btn3.FontSize = 16.0;
        btn3.Content = "Control font size changes from 10 to 16.";
Private Sub ChangeFontSize(ByVal Sender As Object, ByVal e As RoutedEventArgs)

    fsize = btn3.FontSize
    If (fsize = 16.0) Then

        btn3.FontSize = 10.0
        btn3.Content = "FontSize"


        btn3.FontSize = 16.0
        btn3.Content = "Control font size changes from 10 to 16."
    End If
End Sub


這個屬性只會影響的控制項的範本會使用FontSize屬性做為參數。This property only affects a control whose template uses the FontSize property as a parameter. 其他控制項,這個屬性會造成任何影響。On other controls, this property has no impact.

相依性屬性資訊Dependency Property Information

識別項欄位Identifier field FontSizeProperty
若要設定的中繼資料屬性 trueMetadata properties set to true AffectsMeasure, AffectsRender, InheritsAffectsMeasure, AffectsRender, Inherits

XAML Attribute UsageXAML Attribute Usage

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



字串表示Double值。A string representation of a Double value. 這會解譯為裝置獨立單位 (1/96 英吋)device-independent unit (1/96th inch)度量。This is interpreted as a 裝置獨立單位 (1/96 英吋)device-independent unit (1/96th inch) measurement. 字串不需要明確包含小數位數。Strings need not explicitly include decimal points. 例如,值1是可以接受的。For example, a value of 1 is acceptable.

相同Double屬性值部分中提及的範圍限制適用於此處。The same Double range restrictions that are mentioned in the Property Value section apply here.

A值,如先前所述也就是後面接著一個這些單位宣告字串: pxincmptA double value as previously described that is followed by one of these unit declaration strings: px, in, cm, pt.

px (預設值) 裝置獨立單位 (每單位 1/96 英吋)device-independent units (1/96th inch per unit)px (default) is 裝置獨立單位 (每單位 1/96 英吋)device-independent units (1/96th inch per unit)

in 是英吋為單位;1in = = 96pxin is inches; 1in==96px

cm 是公釐。1cm==(96/2.54) 像素cm is centimeters; 1cm==(96/2.54) px

pt is points; 1pt==(96/72) pxpt is points; 1pt==(96/72) px

附註在許多情況下,雙精度浮點數可能會設定為 「 自動 」,但Control.FontSize不會呈現如果設定為 「 自動 」。Note In many cases a double may be set to "Auto," but a Control.FontSize does not render if set to "Auto".