Export (0) Print
Expand All

WebControl.Font Property

Gets the font properties associated with the Web server control.

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)

public virtual FontInfo Font { get; }
/** @property */
public FontInfo get_Font ()

public function get Font () : FontInfo

Property Value

A FontInfo that represents the font properties of the Web server control.

Use the Font property to specify the font properties of the Web Server control. This property includes subproperties that can be accessed declaratively in the form of Property-Subproperty (for example Font-Bold) or programmatically in the form of Property.Subproperty (for example Font.Bold).

All but one subproperty will render in browsers prior to Microsoft Internet Explorer version 4 for all controls. They are: Bold, Italic, Name, Names, Strikeout, Underline, and Size (but only named font sizes, such as Small, Smaller, and so on, will work).

NoteNote

Although these subproperties render in browsers prior to Microsoft Internet Explorer version 4, the HTML that is rendered is different than later browsers. Instead of rendering as style attributes, these subproperties are rendered as HTML elements, such as <b> and <font>.

The one subproperty that will not render on earlier browsers for all controls is Overline.

The following example illustrates how to use the Font property to gather font information from a Label control.

NoteNote

The following code sample uses the single-file code model and may not work correctly if copied directly into a code-behind file. This code sample must be copied into an empty text file that has an .aspx extension. For more information on the Web Forms code model, see ASP.NET Web Page Code Model.

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

<html>
 <head>
    <script language="C#" runat="server">
 
        void Button1_Click(Object sender, EventArgs e) {
           Label1.Text = "The font this label uses is: " + Label1.Font.ToString();
        }
 
        void Button2_Click(Object sender, EventArgs e) {
           Label1.Font.Underline = true;
        }
 
 
    </script>
 
 </head>
 <body>
    <h3>FontUnit Property of a Web Control</h3>
 <form runat="server">
 
    <asp:Label id="Label1" 
     Font-Name="Verdana" Font-Size="10pt"
     Text="This is a Label control."
     runat="server"/>  
 
    <p>
    <asp:Button id="Button1"
     Text="Click to gather font info of the label control"
     OnClick="Button1_Click" 
     Width="300px"
     runat="server"/>
 
    <p>
    <asp:Button id="Button2"
     Text="Click to underline the text of the label control"
     OnClick="Button2_Click" 
     Width="300px"
     runat="server"/>
 
 </form>
 </body>
 </html>
 

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft