共用方式為


Fonts.GetFontFamilies 方法

定義

從指定的字型位置傳回 FontFamily 物件的集合。

多載

GetFontFamilies(String)

從表示字型位置的字串值傳回 FontFamily 物件的集合。

GetFontFamilies(Uri)

從表示字型位置的統一資源識別項 (URI) 值,傳回 FontFamily 物件的集合。

GetFontFamilies(Uri, String)

使用基底統一資源識別項值傳回 FontFamily 物件的集合以解析字型位置。

GetFontFamilies(String)

從表示字型位置的字串值傳回 FontFamily 物件的集合。

public:
 static System::Collections::Generic::ICollection<System::Windows::Media::FontFamily ^> ^ GetFontFamilies(System::String ^ location);
public static System.Collections.Generic.ICollection<System.Windows.Media.FontFamily> GetFontFamilies (string location);
static member GetFontFamilies : string -> System.Collections.Generic.ICollection<System.Windows.Media.FontFamily>
Public Shared Function GetFontFamilies (location As String) As ICollection(Of FontFamily)

參數

location
String

包含字型的位置。

傳回

ICollection<FontFamily>

ICollection<T>FontFamily 物件,表示 location 中的字型。

例外狀況

locationnull。 因為此參數會被視為路徑或 URI,所以您無法傳遞 null

範例

下列範例示範如何使用這個方法,從字型位置傳回物件的集合 FontFamily

// Return the font family collection for the selected directory location.
System.Collections.Generic.ICollection<FontFamily> fontFamilies = Fonts.GetFontFamilies("C:/MyFonts");

// Enumerate through the font family collection.
foreach (FontFamily fontFamily in fontFamilies)
{
    // Separate the URI directory source info from the font family name.
    string[] familyName = fontFamily.Source.Split('#');

    // Add the font family name to the fonts combo box.
    comboBoxFonts.Items.Add(familyName[familyName.Length - 1]);
}

comboBoxFonts.SelectedIndex = 0;
' Return the font family collection for the selected directory location.
Dim fontFamilies As System.Collections.Generic.ICollection(Of FontFamily) = Fonts.GetFontFamilies("C:/MyFonts")

' Enumerate through the font family collection.
For Each fontFamily As FontFamily In fontFamilies
    ' Separate the URI directory source info from the font family name.
    Dim familyName() As String = fontFamily.Source.Split("#"c)

    ' Add the font family name to the fonts combo box.
    comboBoxFonts.Items.Add(familyName(familyName.Length - 1))
Next fontFamily

comboBoxFonts.SelectedIndex = 0

適用於

GetFontFamilies(Uri)

從表示字型位置的統一資源識別項 (URI) 值,傳回 FontFamily 物件的集合。

public:
 static System::Collections::Generic::ICollection<System::Windows::Media::FontFamily ^> ^ GetFontFamilies(Uri ^ baseUri);
public static System.Collections.Generic.ICollection<System.Windows.Media.FontFamily> GetFontFamilies (Uri baseUri);
static member GetFontFamilies : Uri -> System.Collections.Generic.ICollection<System.Windows.Media.FontFamily>
Public Shared Function GetFontFamilies (baseUri As Uri) As ICollection(Of FontFamily)

參數

baseUri
Uri

字型位置的基底 URI 值。

傳回

ICollection<FontFamily>

ICollection<T>FontFamily 物件,表示 baseUri 中的字型。

範例

下列範例示範如何使用這個方法,從基底 URI 位置傳回物件的集合 FontFamily

foreach (FontFamily fontFamily in Fonts.GetFontFamilies("file:///D:/MyFonts/"))
{
    // Perform action.
}
For Each fontFamily As FontFamily In Fonts.GetFontFamilies("file:///D:/MyFonts/")
    ' Perform action.
Next fontFamily

若要傳回應用程式資源中的物件集合 FontFamily ,請使用下列範例所示的「pack://application」 URI 標記法。

foreach (FontFamily fontFamily in Fonts.GetFontFamilies(new Uri("pack://application:,,,/")))
{
    // Perform action.
}
For Each fontFamily As FontFamily In Fonts.GetFontFamilies(New Uri("pack://application:,,,/"))
    ' Perform action.
Next fontFamily

適用於

GetFontFamilies(Uri, String)

使用基底統一資源識別項值傳回 FontFamily 物件的集合以解析字型位置。

public:
 static System::Collections::Generic::ICollection<System::Windows::Media::FontFamily ^> ^ GetFontFamilies(Uri ^ baseUri, System::String ^ location);
public static System.Collections.Generic.ICollection<System.Windows.Media.FontFamily> GetFontFamilies (Uri baseUri, string location);
static member GetFontFamilies : Uri * string -> System.Collections.Generic.ICollection<System.Windows.Media.FontFamily>
Public Shared Function GetFontFamilies (baseUri As Uri, location As String) As ICollection(Of FontFamily)

參數

baseUri
Uri

字型位置的基底 URI 值。

location
String

包含字型的位置。

傳回

ICollection<FontFamily>

ICollection<T> 物件的 FontFamily,表示所解析之字型位置中的字型。

範例

下列範例示範如何使用這個方法,從解析的 FontFamily 字型位置傳回物件的集合。 在此案例中,應用程式包含名為 "resources"的子目錄。

foreach (FontFamily fontFamily in Fonts.GetFontFamilies(new Uri("pack://application:,,,/"), "./resources/"))
{
    // Perform action.
}
For Each fontFamily As FontFamily In Fonts.GetFontFamilies(New Uri("pack://application:,,,/"), "./resources/")
    ' Perform action.
Next fontFamily

適用於