FontInfo 类

定义

封装文本的字体属性。Encapsulates the font properties of text. 此类不能被继承。This class cannot be inherited.

public ref class FontInfo sealed
[System.ComponentModel.TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))]
public sealed class FontInfo
type FontInfo = class
Public NotInheritable Class FontInfo
继承
FontInfo
属性

示例

下面的代码示例演示如何以编程方式修改FontInfo对象的属性, 以指定Label控件的字体属性。The following code example demonstrates how to modify the properties of a FontInfo object programmatically to specify the font properties for a Label control.

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

  void Page_Load(object sender, EventArgs e)
  {
    // When the page loads, set the myLabel Label control's FontInfo properties.
    // Note that myLabel.Font is a FontInfo object.
    
    myLabel.Font.Bold = true;
    myLabel.Font.Italic = false;
    myLabel.Font.Name = "verdana";
    myLabel.Font.Overline = false;
    myLabel.Font.Size = 10;
    myLabel.Font.Strikeout = false;
    myLabel.Font.Underline = true;
    
    // Write information on the FontInfo object to the myLabel label.
    myLabel.Text = myLabel.Font.ToString();
    
  }

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>FontInfo Example</title>
</head>
  <body>
    <form id="form1" runat="server">
    <h3>FontInfo Example</h3>
      <asp:Label id="myLabel" 
        runat="server" >
      </asp:Label>
    </form>
  </body>
</html>
<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

  Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
  
    ' When the page loads, set the myLabel Label control's FontInfo properties.
    ' Note that myLabel.Font is a FontInfo object.
    
    myLabel.Font.Bold = True
    myLabel.Font.Italic = False
    myLabel.Font.Name = "verdana"
    myLabel.Font.Overline = False
    myLabel.Font.Size = 10
    myLabel.Font.Strikeout = False
    myLabel.Font.Underline = True
    
    ' Write information on the FontInfo object to the myLabel label.
    myLabel.Text = myLabel.Font.ToString()
    
  End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>FontInfo Example</title>
</head>
  <body>
    <form id="form1" runat="server">
    <h3>FontInfo Example</h3>
      <asp:Label id="myLabel" 
        runat="server" >
      </asp:Label>
    </form>
  </body>
</html>

注解

FontInfo使用类封装文本的字体属性。Use the FontInfo class to encapsulate the font properties of text. 可以指定字体名称和字体大小。You can specify the font name and font size. 还可以指定字体样式为粗体、斜体、带上划线、删除线或下划线。You can also specify whether the style of the font is bold, italic, overlined, strikethrough, or underlined.

此类通常用于需要字体信息 (如Font WebControl类的属性) 的类的属性中。This class is commonly used in a property for a class that requires font information, such as the Font property of the WebControl class.

备注

此类没有公共构造函数。This class does not have a public constructor. 不能直接创建类的新实例。A new instance of the class cannot be created directly.

属性

Bold

获取或设置一个值,该值指示字体是否为粗体。Gets or sets a value that indicates whether the font is bold.

Italic

获取或设置一个值,该值指示字体是否为斜体。Gets or sets a value that indicates whether the font is italic.

Name

获取或设置主要字体名称。Gets or sets the primary font name.

Names

获取或设置字体名称的排序数组。Gets or sets an ordered array of font names.

Overline

获取或设置一个值,该值指示字体是否带上划线。Gets or sets a value that indicates whether the font is overlined.

Size

获取或设置字号。Gets or sets the font size.

Strikeout

获取或设置一个值,该值指示字体是否带删除线。Gets or sets a value that indicates whether the font is strikethrough.

Underline

获取或设置一个值,该值指示字体是否带下划线。Gets or sets a value that indicates whether the font is underlined.

方法

ClearDefaults()

将所有 FontInfo 属性重置为未设置状态并清除视图状态。Resets all FontInfo properties to the unset state and clears the view state.

CopyFrom(FontInfo)

将指定的 FontInfo 的字体属性复制到调用该方法的 FontInfo 类的实例中。Duplicates the font properties of the specified FontInfo into the instance of the FontInfo class that this method is called from.

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
MergeWith(FontInfo)

将指定的 FontInfo 的字体属性与从中调用此方法的 FontInfo 类的实例相结合。Combines the font properties of the specified FontInfo with the instance of the FontInfo class that this method is called from.

ShouldSerializeNames()

确定是否应保持 Names 属性。Determines whether the Names property should be persisted.

ToString()

返回一个字符串,该字符串包含 FontInfo 类的实例的字体名称和大小。Returns a string that contains the font name and size for an instance of the FontInfo class.

适用于

另请参阅