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

定义

获取或设置字号。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; }
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" 
        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 属性用法XAML Attribute Usage

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

XAML 值XAML Values

doubledouble
Double

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.

qualifiedDoublequalifiedDouble
前面所述的双精度值, 后面跟有以下单元声明字符串之一: 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".

适用于