Control.FontSize 屬性

定義

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

public:
 property double FontSize { double get(); void set(double value); };
[System.ComponentModel.Bindable(true)]
[System.ComponentModel.TypeConverter(typeof(System.Windows.FontSizeConverter))]
[System.Windows.Localizability(System.Windows.LocalizationCategory.None)]
public double FontSize { get; set; }
[<System.ComponentModel.Bindable(true)>]
[<System.ComponentModel.TypeConverter(typeof(System.Windows.FontSizeConverter))>]
[<System.Windows.Localizability(System.Windows.LocalizationCategory.None)>]
member this.FontSize : double with get, set
Public Property FontSize As Double

屬性值

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" 
        Click="ChangeFontSize">
  FontSize
</Button>
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.";
    }
}
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"

    Else

        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"/>  

XAML 值XAML Values

doubledouble
Double

值的字串表示 DoubleA 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.

qualifiedDoublequalifiedDouble
如先前所述的 double 值,後面接著下列其中一個單元宣告字串: 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) pxcm is centimeters; 1cm==(96/2.54) px

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

注意 在許多情況下,double 可能會設定為 "Auto",但 Control.FontSize 如果設定為 "auto",則不會呈現。Note In many cases a double may be set to "Auto," but a Control.FontSize does not render if set to "Auto".

適用於