This documentation is archived and is not being maintained.

FontInfo.Name Property

Gets or sets the primary font name.

[Visual Basic]
Public Property Name As String
[C#]
public string Name {get; set;}
[C++]
public: __property String* get_Name();
public: __property void set_Name(String*);
[JScript]
public function get Name() : String;
public function set Name(String);

Property Value

The primary font name. The default value is String.Empty, which indicates that this property is not set.

Exceptions

Exception Type Condition
ArgumentException The specified font name is a null reference (Nothing in Visual Basic).

Remarks

Use the Name property to specify or determine the primary font name. The primary font name determines the font that is used to display text in the control associated with the FontInfo.

Note   When you set the Names property, the Name property is automatically updated with the first item in the Names property. If you set the Name property, the Names property is automatically updated with a single element array containing the value of the Name property.

Example

[Visual Basic, C#, JScript] The following example demonstrates how to use the Name property to programmatically specify the font name for a Label control.

[Visual Basic] 
<%@ Page Language="VB" AutoEventWireup="True" %>

<html>

   <head>

      <script runat="server">
        
         Sub DisplayFontInfo(sender As Object, e As EventArgs)

            ' Note that the SampleTextLabel.Font property is a FontInfo. 

            ' Display the values of the font.
            NameTextBox.Text = SampleTextLabel.Font.Name
            SizeTextBox.Text = SampleTextLabel.Font.Size.ToString()        
            BoldCheckBox.Checked = SampleTextLabel.Font.Bold
            ItalicCheckBox.Checked = SampleTextLabel.Font.Italic
            OverlineCheckBox.Checked = SampleTextLabel.Font.Overline
            StrikeoutCheckBox.Checked = SampleTextLabel.Font.Strikeout
            UnderlineCheckBox.Checked = SampleTextLabel.Font.Underline
    
            ToStringOutputLabel.Text = SampleTextLabel.Font.ToString()

         End Sub

         Sub SetFontInfo(sender As Object, e As EventArgs)

            ' Note that the SampleTextLabel.Font property is a FontInfo. 

            ' Set the values of the font.
            SampleTextLabel.Font.Name = NameTextBox.Text
            SampleTextLabel.Font.Size = FontUnit.Parse(SizeTextBox.Text)         
            SampleTextLabel.Font.Bold = BoldCheckBox.Checked
            SampleTextLabel.Font.Italic = ItalicCheckBox.Checked
            SampleTextLabel.Font.Overline = OverlineCheckBox.Checked
            SampleTextLabel.Font.Strikeout = StrikeoutCheckBox.Checked
            SampleTextLabel.Font.Underline = UnderlineCheckBox.Checked

         End Sub

      </script>

   </head>

   <body>

      <form runat="server">

         <h3> FontInfo Example </h3>

         <asp:Label  id="SampleTextLabel" 
              Text="Sample Text" 
              Font-Bold="true" 
              Font-Italic="true" 
              Font-Name="Courier" 
              Font-Underline="true"  
              Font-Size="20px"  
              Font-Strikeout="false" 
              runat="server" />

         <br><br>

         <asp:Button id="DisplayButton" 
              Text="Display FontInfo"
              OnClick="DisplayFontInfo" 
              runat="server" />

         <asp:Button id="SetButton"
              Text="Set FontInfo"  
              OnClick="SetFontInfo" 
              runat="server" />

         <br><br>

         Name: 
         <asp:textbox  
              id="NameTextBox" 
              runat="server" />

         <br>

         Size: 
         <asp:textbox  
              id="SizeTextBox" 
              runat="server" />

         <br>

         <asp:CheckBox  
              id="BoldCheckBox" 
              Text="Bold" 
              runat="server" />

         <br>

         <asp:CheckBox  
              id="ItalicCheckBox" 
              Text="Italic" 
              runat="server" />

         <br>

         <asp:CheckBox  
              id="OverlineCheckBox" 
              Text="Overline" runat="server" />

         <br>

         <asp:CheckBox  
              id="StrikeoutCheckBox" 
              Text="Strikeout" 
              runat="server" />

         <br>

         <asp:CheckBox  
              id="UnderlineCheckBox" 
              Text="Underline" runat="server" />

         <br><br>

         <h4>FontInfo.ToString() output:</h4>

         <asp:Label id="ToStringOutputLabel" 
              runat="server" />

      </form>

   </body>

</html>

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

<html>

   <head>

      <script runat="server">
        
         void DisplayFontInfo(Object sender, EventArgs e)
         {

            // Note that the SampleTextLabel.Font property is a FontInfo. 

            // Display the values of the font.
            NameTextBox.Text = SampleTextLabel.Font.Name;
            SizeTextBox.Text = SampleTextLabel.Font.Size.ToString();        
            BoldCheckBox.Checked = SampleTextLabel.Font.Bold;
            ItalicCheckBox.Checked = SampleTextLabel.Font.Italic;
            OverlineCheckBox.Checked = SampleTextLabel.Font.Overline;
            StrikeoutCheckBox.Checked = SampleTextLabel.Font.Strikeout;
            UnderlineCheckBox.Checked = SampleTextLabel.Font.Underline;
    
            ToStringOutputLabel.Text = SampleTextLabel.Font.ToString();

         }

         void SetFontInfo(Object sender, EventArgs e)
         {

            // Note that the SampleTextLabel.Font property is a FontInfo. 

            // Set the values of the font.
            SampleTextLabel.Font.Name = NameTextBox.Text;
            SampleTextLabel.Font.Size = FontUnit.Parse(SizeTextBox.Text);         
            SampleTextLabel.Font.Bold = BoldCheckBox.Checked;
            SampleTextLabel.Font.Italic = ItalicCheckBox.Checked;
            SampleTextLabel.Font.Overline = OverlineCheckBox.Checked;
            SampleTextLabel.Font.Strikeout = StrikeoutCheckBox.Checked;
            SampleTextLabel.Font.Underline = UnderlineCheckBox.Checked;

         }

      </script>

   </head>

   <body>

      <form runat="server">

         <h3> FontInfo Example </h3>

         <asp:Label  id="SampleTextLabel" 
              Text="Sample Text" 
              Font-Bold="true" 
              Font-Italic="true" 
              Font-Name="Courier" 
              Font-Underline="true"  
              Font-Size="20px"  
              Font-Strikeout="false" 
              runat="server" />

         <br><br>

         <asp:Button id="DisplayButton" 
              Text="Display FontInfo"
              OnClick="DisplayFontInfo" 
              runat="server" />

         <asp:Button id="SetButton"
              Text="Set FontInfo"  
              OnClick="SetFontInfo" 
              runat="server" />

         <br><br>

         Name: 
         <asp:textbox  
              id="NameTextBox" 
              runat="server" />

         <br>

         Size: 
         <asp:textbox  
              id="SizeTextBox" 
              runat="server" />

         <br>

         <asp:CheckBox  
              id="BoldCheckBox" 
              Text="Bold" 
              runat="server" />

         <br>

         <asp:CheckBox  
              id="ItalicCheckBox" 
              Text="Italic" 
              runat="server" />

         <br>

         <asp:CheckBox  
              id="OverlineCheckBox" 
              Text="Overline" runat="server" />

         <br>

         <asp:CheckBox  
              id="StrikeoutCheckBox" 
              Text="Strikeout" 
              runat="server" />

         <br>

         <asp:CheckBox  
              id="UnderlineCheckBox" 
              Text="Underline" runat="server" />

         <br><br>

         <h4>FontInfo.ToString() output:</h4>

         <asp:Label id="ToStringOutputLabel" 
              runat="server" />

      </form>

   </body>

</html>

[JScript] 
<%@ Page Language="JScript" AutoEventWireup="True" %>

<html>

   <head>

      <script runat="server">
        
         function DisplayFontInfo(sender, e : EventArgs)
         {

            // Note that the SampleTextLabel.Font property is a FontInfo. 

            // Display the values of the font.
            NameTextBox.Text = SampleTextLabel.Font.Name;
            SizeTextBox.Text = SampleTextLabel.Font.Size.ToString();        
            BoldCheckBox.Checked = SampleTextLabel.Font.Bold;
            ItalicCheckBox.Checked = SampleTextLabel.Font.Italic;
            OverlineCheckBox.Checked = SampleTextLabel.Font.Overline;
            StrikeoutCheckBox.Checked = SampleTextLabel.Font.Strikeout;
            UnderlineCheckBox.Checked = SampleTextLabel.Font.Underline;
    
            ToStringOutputLabel.Text = SampleTextLabel.Font.ToString();

         }

         function SetFontInfo(sender, e : EventArgs)
         {

            // Note that the SampleTextLabel.Font property is a FontInfo. 

            // Set the values of the font.
            SampleTextLabel.Font.Name = NameTextBox.Text;
            SampleTextLabel.Font.Size = FontUnit.Parse(SizeTextBox.Text);         
            SampleTextLabel.Font.Bold = BoldCheckBox.Checked;
            SampleTextLabel.Font.Italic = ItalicCheckBox.Checked;
            SampleTextLabel.Font.Overline = OverlineCheckBox.Checked;
            SampleTextLabel.Font.Strikeout = StrikeoutCheckBox.Checked;
            SampleTextLabel.Font.Underline = UnderlineCheckBox.Checked;

         }

      </script>

   </head>

   <body>

      <form runat="server">

         <h3> FontInfo Example </h3>

         <asp:Label  id="SampleTextLabel" 
              Text="Sample Text" 
              Font-Bold="true" 
              Font-Italic="true" 
              Font-Name="Courier" 
              Font-Underline="true"  
              Font-Size="20px"  
              Font-Strikeout="false" 
              runat="server" />

         <br><br>

         <asp:Button id="DisplayButton" 
              Text="Display FontInfo"
              OnClick="DisplayFontInfo" 
              runat="server" />

         <asp:Button id="SetButton"
              Text="Set FontInfo"  
              OnClick="SetFontInfo" 
              runat="server" />

         <br><br>

         Name: 
         <asp:textbox  
              id="NameTextBox" 
              runat="server" />

         <br>

         Size: 
         <asp:textbox  
              id="SizeTextBox" 
              runat="server" />

         <br>

         <asp:CheckBox  
              id="BoldCheckBox" 
              Text="Bold" 
              runat="server" />

         <br>

         <asp:CheckBox  
              id="ItalicCheckBox" 
              Text="Italic" 
              runat="server" />

         <br>

         <asp:CheckBox  
              id="OverlineCheckBox" 
              Text="Overline" runat="server" />

         <br>

         <asp:CheckBox  
              id="StrikeoutCheckBox" 
              Text="Strikeout" 
              runat="server" />

         <br>

         <asp:CheckBox  
              id="UnderlineCheckBox" 
              Text="Underline" runat="server" />

         <br><br>

         <h4>FontInfo.ToString() output:</h4>

         <asp:Label id="ToStringOutputLabel" 
              runat="server" />

      </form>

   </body>

</html>

[C++] No example is available for C++. To view a Visual Basic, C#, or JScript example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

See Also

FontInfo Class | FontInfo Members | System.Web.UI.WebControls Namespace | Bold | Italic | Names | Overline | Size | Strikeout | Underline

Show: