FontNamesConverter.ConvertFrom Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Convertit une chaîne qui représente une liste de noms de polices en un tableau de chaînes contenant des noms de police individuels.
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
Paramètres
- context
- ITypeDescriptorContext
Objet ITypeDescriptorContext qui fournit des informations sur le contexte d’un convertisseur de type. Ce paramètre n’est pas utilisé dans cette méthode. Elle est réservée aux futures versions de cette méthode. Vous pouvez éventuellement passer null pour ce paramètre.
- culture
- CultureInfo
Objet CultureInfo qui représente des informations sur une culture telle que la langue, le système de calendrier, etc. Ce paramètre n’est pas utilisé dans cette méthode. Elle est réservée aux futures versions de cette méthode. Vous pouvez éventuellement passer null pour ce paramètre.
Retours
Instance Object qui représente le tableau de chaînes contenant les noms de police individuels.
Exceptions
value n’est pas de type String.
Exemples
L’exemple de code suivant montre comment utiliser la ConvertFrom méthode pour convertir une chaîne avec une liste de noms de polices en tableau de chaînes contenant les noms individuels.
<%@ 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>
Remarques
Utilisez la ConvertFrom méthode pour convertir une chaîne contenant une liste de noms de polices en tableau de chaînes contenant les noms individuels. Chaque nom de police dans la chaîne doit être séparé par une virgule. Par exemple, la chaîne « arial, times new roman, verdana », se convertit en tableau qui contient les chaînes « arial », « times new roman » et « verdana ». Notez que les virgules sont supprimées avec n’importe quel espace blanc au début ou à la fin du nom de police. L’espace blanc au milieu d’un nom de police n’est pas supprimé.
Note
Les context paramètres et culture les paramètres ne sont pas utilisés dans cette version de la méthode ; ils sont réservés aux futures versions de la méthode. Vous pouvez éventuellement passer null pour ces paramètres.