InstalledFontCollection 类从 FontCollection 抽象基类继承。可使用 InstalledFontCollection 对象枚举计算机上安装的字体。InstalledFontCollection 对象的 Families 属性是 FontFamily 对象的一个数组。下面的示例列出计算机上安装的所有字体系列的名称。该代码在 Families 属性返回的数组中检索每个 FontFamily 对象的 Name 属性。检索到字体系列名称时,将它们连接起来以形成用逗号分隔的列表。然后,Graphics 类的 DrawString 方法在矩形中绘制此用逗号分隔的列表。[Visual Basic] Dim fontFamily As New FontFamily("Arial") Dim font As New Font( _ fontFamily, _ 8, _ FontStyle.Regular, _ GraphicsUnit.Point) Dim rectF As New RectangleF(10, 10, 500, 500) Dim solidBrush As New SolidBrush(Color.Black)Dim familyName As String Dim familyList As String = "" Dim fontFamilies() As FontFamilyDim installedFontCollection As New InstalledFontCollection()' Get the array of FontFamily objects. fontFamilies = installedFontCollection.Families' The loop below creates a large string that is a comma-separated ' list of all font family names. Dim count As Integer = fontFamilies.Length Dim j As IntegerWhile j < count familyName = fontFamilies(j).Name familyList = familyList + familyName familyList = familyList + ", " End While' Draw the large string (list of all families) in a rectangle. e.Graphics.DrawString(familyList, font, solidBrush, rectF) [C#] FontFamily fontFamily = new FontFamily("Arial"); Font font = new Font( fontFamily, 8, FontStyle.Regular, GraphicsUnit.Point); RectangleF rectF = new RectangleF(10, 10, 500, 500); SolidBrush solidBrush = new SolidBrush(Color.Black);string familyName; string familyList = ""; FontFamily[] fontFamilies;InstalledFontCollection installedFontCollection = new InstalledFontCollection();// Get the array of FontFamily objects. fontFamilies = installedFontCollection.Families;// The loop below creates a large string that is a comma-separated // list of all font family names.int count = fontFamilies.Length; for(int j = 0; j < count; ++j) { familyName = fontFamilies[j].Name; familyList = familyList + familyName; familyList = familyList + ", "; }// Draw the large string (list of all families) in a rectangle. e.Graphics.DrawString(familyList, font, solidBrush, rectF);
搞定了 谢谢各位了 现在结贴Dim clsInstalledFontCollection As System.Drawing.Text.InstalledFontCollection Dim affInstalledFont As System.Drawing.FontFamily() Dim clsFontFamily As System.Drawing.FontFamily clsInstalledFontCollection = New System.Drawing.Text.InstalledFontCollection() affInstalledFont = clsInstalledFontCollection.Families For Each clsFontFamily In affInstalledFont ddlFont.Items.Add(New ListItem(clsFontFamily.Name, clsFontFamily.Name)) Next
给个例子好吗,我不大会做。拜托拜托 *_*
Dim fontFamily As New FontFamily("Arial")
Dim font As New Font( _
fontFamily, _
8, _
FontStyle.Regular, _
GraphicsUnit.Point)
Dim rectF As New RectangleF(10, 10, 500, 500)
Dim solidBrush As New SolidBrush(Color.Black)Dim familyName As String
Dim familyList As String = ""
Dim fontFamilies() As FontFamilyDim installedFontCollection As New InstalledFontCollection()' Get the array of FontFamily objects.
fontFamilies = installedFontCollection.Families' The loop below creates a large string that is a comma-separated
' list of all font family names.
Dim count As Integer = fontFamilies.Length
Dim j As IntegerWhile j < count
familyName = fontFamilies(j).Name
familyList = familyList + familyName
familyList = familyList + ", "
End While' Draw the large string (list of all families) in a rectangle.
e.Graphics.DrawString(familyList, font, solidBrush, rectF)
[C#]
FontFamily fontFamily = new FontFamily("Arial");
Font font = new Font(
fontFamily,
8,
FontStyle.Regular,
GraphicsUnit.Point);
RectangleF rectF = new RectangleF(10, 10, 500, 500);
SolidBrush solidBrush = new SolidBrush(Color.Black);string familyName;
string familyList = "";
FontFamily[] fontFamilies;InstalledFontCollection installedFontCollection = new InstalledFontCollection();// Get the array of FontFamily objects.
fontFamilies = installedFontCollection.Families;// The loop below creates a large string that is a comma-separated
// list of all font family names.int count = fontFamilies.Length;
for(int j = 0; j < count; ++j)
{
familyName = fontFamilies[j].Name;
familyList = familyList + familyName;
familyList = familyList + ", ";
}// Draw the large string (list of all families) in a rectangle.
e.Graphics.DrawString(familyList, font, solidBrush, rectF);
现在结贴Dim clsInstalledFontCollection As System.Drawing.Text.InstalledFontCollection
Dim affInstalledFont As System.Drawing.FontFamily()
Dim clsFontFamily As System.Drawing.FontFamily clsInstalledFontCollection = New System.Drawing.Text.InstalledFontCollection()
affInstalledFont = clsInstalledFontCollection.Families
For Each clsFontFamily In affInstalledFont
ddlFont.Items.Add(New ListItem(clsFontFamily.Name, clsFontFamily.Name))
Next