private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
g.Clear(Color.White);
g.SmoothingMode = SmoothingMode.AntiAlias;
//定义输出字体
Font myFont = new Font("Arial", 15, FontStyle.Regular, GraphicsUnit.Pixel);
//定义文本输出格式
StringFormat strFmt = new StringFormat();
strFmt.Alignment = StringAlignment.Near;
strFmt.LineAlignment = StringAlignment.Near;
string tempStr = string.Empty;
//获取系统所有已安装的字体系列
InstalledFontCollection installedCollection = new InstalledFontCollection();
FontFamily[] fontFamilyArray = installedCollection.Families;
int index = 0;
//访问 fontFamilyArray 数组中的每一个成员
foreach (FontFamily i in fontFamilyArray)
{
//获取当前字体系统的名称
tempStr += i.Name + ",";
index++;
}
//绘制所有字体
Rectangle textOutRect = new Rectangle(0, 15, Width, Height);
g.DrawString(tempStr, myFont, Brushes.Black, textOutRect, strFmt);
tempStr = string.Format("系统中已经安装的字体有{0}种,其名称分别为:\n", index + 1);
g.DrawString(tempStr,myFont,Brushes.Red,new PointF(0,0));
}
效果图: