FontNamesConverter 類別

定義

在包含字型名稱清單的字串與代表個別名稱的字串陣列之間轉換。Converts between a string containing a list of font names and an array of strings representing the individual names.

public ref class FontNamesConverter : System::ComponentModel::TypeConverter
public class FontNamesConverter : System.ComponentModel.TypeConverter
type FontNamesConverter = class
    inherit TypeConverter
Public Class FontNamesConverter
Inherits TypeConverter
繼承
FontNamesConverter

範例

下列程式碼範例示範如何使用FontNamesConverter類別, 將具有字型名稱清單的字串, 轉換成包含個別名稱的字串陣列。The following code 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="C#" AutoEventWireup="True" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>FontNamesConverter Example</title>
<script language="C#" runat="server">

      void Page_Load(Object sender, EventArgs e) 
      {

         // Declare local variables.
         System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo("en");
         System.ComponentModel.ITypeDescriptorContext context = null;
         Object names; 
         Object name_string;

         // Create FontNamesConverter object.
         FontNamesConverter fontconverter = new FontNamesConverter();

         // Create original list of fonts.
         string font_list = "arial, times new roman, verdana";

         // Check for type compatibility.
         if (fontconverter.CanConvertFrom(context, typeof(string)))
         {

            // 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 />";
            foreach (string name_element in (string[])names)
            {
               Label2.Text += name_element + "<br />";
            }

            // Convert array of strings back to a string and display results.
            name_string = fontconverter.ConvertTo(context, culture, names, typeof(string)); 
            Label3.Text = "Converted back to String :" + "<br /><br />" + (string)name_string;

         }
          
      }

   </script>

</head>
<body>

   <h3>FontNamesConverter Example</h3>
   <br />

   <form id="form1" 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>
   
<%@ Page Language="VB" AutoEventWireup="True" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>FontNamesConverter Example</title>
<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>
   <br />

   <form id="form1" 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>
   

備註

使用這個ConvertFrom類別的方法, 將包含字型名稱清單的單一字串轉換成包含個別名稱的字串陣列。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. 例如, 字串 "arial, times new roman, verdana", 會轉換成包含字串 "arial"、"times new roman" 和 "verdana" 的陣列。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.

ConvertTo方法會執行反向作業。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. 例如, 包含字串「arial」、「times new roman」和「verdana」的陣列會轉換成字串「arial, times new roman, verdana」。For example, an array that contains the strings "arial", "times new roman", and "verdana" converts to the string "arial,times new roman,verdana". 請注意, 字型名稱之間會自動插入逗號, 而不含任何空白字元。Notice that commas are automatically inserted between the font names without any white space.

呼叫方法, 以確認在ConvertFrom呼叫方法之前可以進行轉換。 CanConvertFromCall the CanConvertFrom method to verify that the conversion can be made before calling the ConvertFrom method.

建構函式

FontNamesConverter()

初始化 FontNamesConverter 類別的新執行個體。Initializes a new instance of the FontNamesConverter class.

方法

CanConvertFrom(ITypeDescriptorContext, Type)

判斷這個轉換子是否能夠轉換指定資料型別的物件成為包含個別字型名稱的字串陣列。Determines whether this converter can convert an object of the specified data type to an array of strings containing individual font names.

CanConvertFrom(Type)

傳回值,指出這個轉換子是否可將指定之型別的物件轉換為這個轉換子的型別。Returns whether this converter can convert an object of the given type to the type of this converter.

(繼承來源 TypeConverter)
CanConvertTo(ITypeDescriptorContext, Type)

傳回這個轉換器是否可以使用指定的內容,將物件轉換成指定的類型。Returns whether this converter can convert the object to the specified type, using the specified context.

(繼承來源 TypeConverter)
CanConvertTo(Type)

傳回值,指出這個轉換子是否可以將物件轉換成指定的型別。Returns whether this converter can convert the object to the specified type.

(繼承來源 TypeConverter)
ConvertFrom(ITypeDescriptorContext, CultureInfo, Object)

轉換表示字型名稱清單的字串為包含個別字型名稱的字串陣列。Converts a string that represents a list of font names into an array of strings containing individual font names.

ConvertFrom(Object)

會將指定值轉換為這個轉換子的型別。Converts the given value to the type of this converter.

(繼承來源 TypeConverter)
ConvertFromInvariantString(ITypeDescriptorContext, String)

會使用不區分的文化特性和指定的內容,將指定的字串轉換為這個轉換子的型別。Converts the given string to the type of this converter, using the invariant culture and the specified context.

(繼承來源 TypeConverter)
ConvertFromInvariantString(String)

會使用不因文化特性而異,將指定字串轉換為這個轉換子的型別。Converts the given string to the type of this converter, using the invariant culture.

(繼承來源 TypeConverter)
ConvertFromString(ITypeDescriptorContext, CultureInfo, String)

會使用指定內容和文化特性資訊,將指定文字轉換為物件。Converts the given text to an object, using the specified context and culture information.

(繼承來源 TypeConverter)
ConvertFromString(ITypeDescriptorContext, String)

會使用指定的內容,將指定文字轉換為物件。Converts the given text to an object, using the specified context.

(繼承來源 TypeConverter)
ConvertFromString(String)

會將指定的文字轉換成物件。Converts the specified text to an object.

(繼承來源 TypeConverter)
ConvertTo(ITypeDescriptorContext, CultureInfo, Object, Type)

從包含個別字型名稱的字串陣列,建立表示字型名稱清單的字串。Creates a string that represents a list of font names from an array of strings containing individual font names.

ConvertTo(Object, Type)

會使用引數,將指定值物件轉換成指定型別。Converts the given value object to the specified type, using the arguments.

(繼承來源 TypeConverter)
ConvertToInvariantString(ITypeDescriptorContext, Object)

會使用指定的內容,將指定值轉換成不因文化特性而異的字串表示。Converts the specified value to a culture-invariant string representation, using the specified context.

(繼承來源 TypeConverter)
ConvertToInvariantString(Object)

會將指定值轉換成不因文化特性而異的字串表示。Converts the specified value to a culture-invariant string representation.

(繼承來源 TypeConverter)
ConvertToString(ITypeDescriptorContext, CultureInfo, Object)

會使用指定的內容和文化特性資訊,將指定值轉換為字串表示。Converts the given value to a string representation, using the specified context and culture information.

(繼承來源 TypeConverter)
ConvertToString(ITypeDescriptorContext, Object)

會使用指定的內容,將指定值轉換為字串表示。Converts the given value to a string representation, using the given context.

(繼承來源 TypeConverter)
ConvertToString(Object)

會將指定值轉換成字串表示。Converts the specified value to a string representation.

(繼承來源 TypeConverter)
CreateInstance(IDictionary)

重新建立 Object,需為物件提供一組屬性值。Re-creates an Object given a set of property values for the object.

(繼承來源 TypeConverter)
CreateInstance(ITypeDescriptorContext, IDictionary)

使用指定的內容,建立與這個 TypeConverter 相關聯之類型的執行個體,並為物件提供一組屬性值。Creates an instance of the type that this TypeConverter is associated with, using the specified context, given a set of property values for the object.

(繼承來源 TypeConverter)
Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
GetConvertFromException(Object)

無法執行轉換時,會傳回要擲回的例外狀況。Returns an exception to throw when a conversion cannot be performed.

(繼承來源 TypeConverter)
GetConvertToException(Object, Type)

無法執行轉換時,會傳回要擲回的例外狀況。Returns an exception to throw when a conversion cannot be performed.

(繼承來源 TypeConverter)
GetCreateInstanceSupported()

傳回值,指出在這個物件上變更值時是否需要呼叫 CreateInstance(IDictionary) 方法來建立新值。Returns whether changing a value on this object requires a call to the CreateInstance(IDictionary) method to create a new value.

(繼承來源 TypeConverter)
GetCreateInstanceSupported(ITypeDescriptorContext)

會使用指定的內容,傳回在這個物件上變更值是否需要呼叫 CreateInstance(IDictionary) 來建立新值。Returns whether changing a value on this object requires a call to CreateInstance(IDictionary) to create a new value, using the specified context.

(繼承來源 TypeConverter)
GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)
GetProperties(ITypeDescriptorContext, Object)

會使用指定的內容,傳回由值參數所指定之陣列型別的屬性集合。Returns a collection of properties for the type of array specified by the value parameter, using the specified context.

(繼承來源 TypeConverter)
GetProperties(ITypeDescriptorContext, Object, Attribute[])

使用指定的內容和屬性 (Attribute),傳回由值參數所指定之陣列型別的屬性 (Property) 集合。Returns a collection of properties for the type of array specified by the value parameter, using the specified context and attributes.

(繼承來源 TypeConverter)
GetProperties(Object)

傳回由值參數所指定之陣列型別的屬性集合。Returns a collection of properties for the type of array specified by the value parameter.

(繼承來源 TypeConverter)
GetPropertiesSupported()

傳回值,指出這個物件是否支援屬性。Returns whether this object supports properties.

(繼承來源 TypeConverter)
GetPropertiesSupported(ITypeDescriptorContext)

會使用指定的內容傳回數值,表示這個物件是否支援屬性。Returns whether this object supports properties, using the specified context.

(繼承來源 TypeConverter)
GetStandardValues()

從為這個型別轉換子所設計的資料型別預設內容中,會傳回標準值的集合。Returns a collection of standard values from the default context for the data type this type converter is designed for.

(繼承來源 TypeConverter)
GetStandardValues(ITypeDescriptorContext)

當有提供格式內容時,會傳回這個型別轉換子設計之資料型別的標準值集合。Returns a collection of standard values for the data type this type converter is designed for when provided with a format context.

(繼承來源 TypeConverter)
GetStandardValuesExclusive()

傳回值,這個值表示從 GetStandardValues() 所傳回的標準值集合是否為獨佔清單。Returns whether the collection of standard values returned from GetStandardValues() is an exclusive list.

(繼承來源 TypeConverter)
GetStandardValuesExclusive(ITypeDescriptorContext)

會使用指定的內容,傳回從 GetStandardValues() 所傳回的標準值集合是否為可能值的獨佔清單。Returns whether the collection of standard values returned from GetStandardValues() is an exclusive list of possible values, using the specified context.

(繼承來源 TypeConverter)
GetStandardValuesSupported()

會傳回這個物件是否支援可以從清單中挑選的標準值組。Returns whether this object supports a standard set of values that can be picked from a list.

(繼承來源 TypeConverter)
GetStandardValuesSupported(ITypeDescriptorContext)

會使用指定的內容傳回,這個物件是否支援可從清單中挑選的標準值集合。Returns whether this object supports a standard set of values that can be picked from a list, using the specified context.

(繼承來源 TypeConverter)
GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
IsValid(ITypeDescriptorContext, Object)

會傳回指定值物件是否對這個型別和指定的內容有效。Returns whether the given value object is valid for this type and for the specified context.

(繼承來源 TypeConverter)
IsValid(Object)

會傳回指定值物件是否對這個型別有效。Returns whether the given value object is valid for this type.

(繼承來源 TypeConverter)
MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(繼承來源 Object)
SortProperties(PropertyDescriptorCollection, String[])

排序屬性的集合。Sorts a collection of properties.

(繼承來源 TypeConverter)
ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)

適用於

另請參閱