FontNamesConverter.ConvertFrom 方法

定義

轉換表示字型名稱清單的字串為包含個別字型名稱的字串陣列。

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 物件,提供關於型別轉換內容的詳細資訊。 這個參數不能使用於這個方法。 它保留做為這個方法的未來版本。 您可以選擇性地為這個參數傳入 null

culture
CultureInfo

CultureInfo 物件,表示關於文化特性的詳細資訊,例如語言、日曆系統等等。 這個參數不能使用於這個方法。 它保留做為這個方法的未來版本。 您可以選擇性地為這個參數傳入 null

value
Object

Object 執行個體,代表要從其中轉換的來源字串。

傳回

Object

Object 執行個體,表示包含個別字型名稱的字串陣列。

例外狀況

value 不是 String 型別。

範例

下列程式碼範例示範如何使用 ConvertFrom 方法,將具有字型名稱清單的字串轉換成包含個別名稱的字串陣列。

<%@ 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使用 方法,將包含字型名稱清單的字串轉換成包含個別名稱的字串陣列。 字串中的每個字型名稱都必須以逗號分隔。 例如,字串 「arial, times new roman, verdana」 會轉換成包含字串 「arial」、「times new roman」 和 「verdana」 的陣列。 請注意,逗號會連同字型名稱開頭或結尾的任何空白字元一起移除。 不會移除字型名稱中間的空白字元。

注意

contextculture 參數不會用於這個版本的 方法;它們會保留給方法的未來版本。 您可以選擇性地傳入 null 這些參數。

適用於

另請參閱