WebControl.Font 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取与 Web 服务器控件关联的字体属性。
public:
virtual property System::Web::UI::WebControls::FontInfo ^ Font { System::Web::UI::WebControls::FontInfo ^ get(); };
public virtual System.Web.UI.WebControls.FontInfo Font { get; }
member this.Font : System.Web.UI.WebControls.FontInfo
Public Overridable ReadOnly Property Font As FontInfo
属性值
FontInfo,表示 Web 服务器控件的字体属性。
示例
下面的示例演示如何使用 Font 属性从 Label 控件收集字体信息。
备注
下面的代码示例使用单文件代码模型,如果直接复制到代码隐藏文件中,可能无法正常工作。 必须将此代码示例复制到具有 .aspx 扩展名的空文本文件中。 有关Web Forms代码模型的详细信息,请参阅 ASP.NET Web Forms页代码模型。
<%@ 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 Button1_Click(object sender, EventArgs e)
{
Label1.Text = "The current font is: " + Label1.Font.ToString();
}
void Button2_Click(object sender, EventArgs e)
{
Label1.Font.Underline = !Label1.Font.Underline;
if (Label1.Font.Name == "Verdana")
Label1.Font.Name = "Times";
else
Label1.Font.Name = "Verdana";
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head2" runat="server">
<title>Enabled Property Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h3>FontUnit Property of a Web Control</h3>
<asp:Label id="Label1" runat="server"
Font-Names="Verdana" Font-Size="10pt"
Text="This is a Label control." />
<p>
<asp:Button id="Button1" runat="server"
Text="Click to display font info"
OnClick="Button1_Click" Width="300px" />
</p>
<p>
<asp:Button id="Button2" runat="server"
Text="Click to change font and underlining"
OnClick="Button2_Click" Width="300px" />
</p>
</div>
</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 Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
Label1.Text = "The current font is: " & Label1.Font.ToString()
End Sub
Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs)
Label1.Font.Underline = Not Label1.Font.Underline
If Label1.Font.Name = "Verdana" Then
Label1.Font.Name = "Times"
Else
Label1.Font.Name = "Verdana"
End If
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head2" runat="server">
<title>Enabled Property Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h3>FontUnit Property of a Web Control</h3>
<asp:Label id="Label1" runat="server"
Font-Names="Verdana" Font-Size="10pt"
Text="This is a Label control." />
<p>
<asp:Button id="Button1" runat="server"
Text="Click to display font info"
OnClick="Button1_Click" Width="300px" />
</p>
<p>
<asp:Button id="Button2" runat="server"
Text="Click to change font and underlining"
OnClick="Button2_Click" Width="300px" />
</p>
</div>
</form>
</body>
</html>
注解
使用属性 Font 指定 Web 服务器控件的字体属性。 此属性包括以声明方式以 (声明方式访问的子属性,例如Font-Bold
,) 或以编程方式以 (的形式Property-Subproperty
Property.Subproperty
访问,例如Font.Bold
) 。
除了一个子属性,还会在所有控件的 Microsoft Internet Explorer 版本 4 之前在浏览器中呈现。 它们包括:Bold、、Italic、、Name、Names、Strikeout (Size Underline,但仅命名字号(例如Small``Smaller
,等等)将) 工作。
备注
尽管这些子属性在 Microsoft Internet Explorer 版本 4 之前的浏览器中呈现,但呈现的 HTML 与更高版本的浏览器不同。 这些子属性不呈现为样式属性,而是呈现为 HTML 元素,例如 <b>
和 <font>
。
不会在所有控件的早期浏览器中呈现的一个子属性是 Overline。