FontNamesConverter.ConvertFrom(ITypeDescriptorContext, CultureInfo, Object) 方法

定義

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

public:
 override System::Object ^ ConvertFrom(System::ComponentModel::ITypeDescriptorContext ^ context, System::Globalization::CultureInfo ^ culture, System::Object ^ value);
public override object ConvertFrom (System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value);
override this.ConvertFrom : System.ComponentModel.ITypeDescriptorContext * System.Globalization.CultureInfo * obj -> obj
Public Overrides Function ConvertFrom (context As ITypeDescriptorContext, culture As CultureInfo, value As Object) As Object

參數

context
ITypeDescriptorContext

ITypeDescriptorContext 物件,提供關於型別轉換內容的詳細資訊。A ITypeDescriptorContext object that provides information about the context of a type converter. 這個參數不能使用於這個方法。This parameter is not used in this method. 它保留做為這個方法的未來版本。It is reserved for future versions of this method. 您可以選擇性地為這個參數傳入 nullYou can optionally pass in null for this parameter.

culture
CultureInfo

CultureInfo 物件,表示關於文化特性的詳細資訊,例如語言、日曆系統等等。A CultureInfo object that represents information about a culture such as language, calendar system, and so on. 這個參數不能使用於這個方法。This parameter is not used in this method. 它保留做為這個方法的未來版本。It is reserved for future versions of this method. 您可以選擇性地為這個參數傳入 nullYou can optionally pass in null for this parameter.

value
Object

Object 執行個體,代表要從其中轉換的來源字串。A Object instance that represents the source string to convert from.

傳回

Object 執行個體,表示包含個別字型名稱的字串陣列。A Object instance that represents the array of strings containing the individual font names.

例外狀況

value 不是 String 型別。value is not of type String.

範例

下列程式碼範例示範如何使用ConvertFrom方法, 將具有字型名稱清單的字串, 轉換成包含個別名稱的字串陣列。The following code example demonstrates how to use the ConvertFrom method to convert a string with a list of font names to an array of strings containing the individual names.

<%@ 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 to convert a 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 that 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.

注意

和參數culture不會用在這個版本的方法中, 而是保留給未來的方法版本。 contextThe context and culture parameters are not used in this version of the method; they are reserved for future versions of the method. 您可以選擇性地傳入null這些參數。You can optionally pass in null for these parameters.

適用於

另請參閱