FontNamesConverter 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
在包含字型名稱清單的字串與代表個別名稱的字串陣列之間轉換。
public ref class FontNamesConverter : System::ComponentModel::TypeConverter
public class FontNamesConverter : System.ComponentModel.TypeConverter
type FontNamesConverter = class
inherit TypeConverter
Public Class FontNamesConverter
Inherits TypeConverter
- 繼承
範例
下列程式代碼範例示範如何使用 FontNamesConverter 類別,將具有字型名稱清單的字串轉換成包含個別名稱的字串陣列。 然後,字串的陣列會轉換成單一字串並顯示。
<%@ 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” 的陣列。 請注意,逗號會連同字型名稱開頭或結尾的任何空格符一起移除。 不會移除字型名稱中間的空格符。
方法 ConvertTo 會執行反向作業。 它會將包含個別字型名稱的字串陣列轉換成包含名稱清單的單一字串。 例如,包含字串 “arial”、“times new roman” 和 “verdana” 的陣列會轉換成字串 “arial,times new roman,verdana”。 請注意,在字型名稱之間會自動插入逗號,而沒有任何空格符。
CanConvertFrom呼叫 方法,以確認可以在呼叫 ConvertFrom 方法之前進行轉換。
建構函式
FontNamesConverter() |
初始化 FontNamesConverter 類別的新執行個體。 |