FontNamesConverter Class
TOC
Collapse the table of content
Expand the table of content

FontNamesConverter Class

Converts a string containing a list of font names to an array of strings containing the individual names. It also performs the reverse function.

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

'Declaration
Public Class FontNamesConverter
	Inherits TypeConverter
'Usage
Dim instance As FontNamesConverter

public class FontNamesConverter extends TypeConverter
public class FontNamesConverter extends TypeConverter

Use the ConvertFrom method of this class to convert a single string containing a list of font names to an array of strings containing the individual names. Each font name in the string must be separated by a comma. For example, the string, "arial, times new roman, verdana", converts to an array that contains the strings "arial", "times new roman", and "verdana". Notice the commas are removed along with any white space at the beginning or end of the font name. White space in the middle of a font name is not removed.

The ConvertTo method performs the reverse operation. It converts an array of strings containing the individual font names to a single string containing a list of the names. For example, an array that contains the strings "arial", "times new roman", and "verdana" converts to the string, "arial,times new roman,verdana". Notice commas are automatically inserted between the font names without any white space.

Use the CanConvertFrom method to verify that the conversion can be made before using the ConvertFrom method.

The following example demonstrates how to use the FontNamesConverter class to convert a string with a list of font names to an array of strings containing the individual names. The array of strings is then converted back to a single string and displayed.

<%@ Page Language="VB" AutoEventWireup="True" %>

<html>
<head>

   <script language="VB" runat="server">
    Sub Page_Load(sender As Object, e As EventArgs)
        
        ' Declare local variables.
        Dim culture As New System.Globalization.CultureInfo("en")
        Dim context As System.ComponentModel.ITypeDescriptorContext = Nothing
        Dim names As Object
        Dim name_string As Object
        
        ' Create FontNamesConverter object.
        Dim fontconverter As New FontNamesConverter()
        
        ' Create original list of fonts.
        Dim font_list As String = "arial, times new roman, verdana"
        
        ' Check for type compatibility.
        If fontconverter.CanConvertFrom(context, GetType(String)) Then
            
            ' Display original string.
            Label1.Text = "Original String :" & "<br><br>" & font_list
            
            ' Convert string to array to strings and display results.
            names = fontconverter.ConvertFrom(context, culture, font_list)
            Label2.Text = "Converted to Array of Strings : " & "<br><br>"
            Dim name_element As String
            For Each name_element In CType(names, String())
                Label2.Text &= name_element & "<br>"
            Next name_element
            
            ' Convert array of strings back to a string and display results.
            name_string = fontconverter.ConvertTo(context, culture, names, _
                GetType(String))
            Label3.Text = "Converted back to String :" & "<br><br>" & _
                CType(name_string, String)
        End If 
    End Sub 'Page_Load
  </script>

</head>
<body>

   <h3>FontNamesConverter Example</h3>
   <p>

   <form runat=server>
        
      <asp:Label id="Label1" runat="server"/>
      <br><hr>
      <asp:Label id="Label2" runat="server"/>
      <br><hr>
      <asp:Label id="Label3" runat="server"/>
        
   </form>

</body>
</html>
   

System.Object
   System.ComponentModel.TypeConverter
    System.Web.UI.WebControls.FontNamesConverter

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

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:
© 2016 Microsoft