读取系统中已安装的字体信息

private void SystemFont()
        {
            //设置窗体的基本属性
            Graphics graphics = CreateGraphics();
            graphics.Clear(Color.White);

            SolidBrush solidbrush = new SolidBrush(Color.Black);
            FontFamily fontfamily = new FontFamily("Arial");
            Font font = new Font(fontfamily, 8, FontStyle.Regular, GraphicsUnit.Point);

            StringFormat fmt = new StringFormat();
            fmt.Alignment = StringAlignment.Near;
            fmt.LineAlignment = StringAlignment.Near;

            //调用InstalledFontCollection类读取系统已安装的字体
            string tmp = "";
            InstalledFontCollection installedfontcollection = new InstalledFontCollection();
            FontFamily[] fontfamilies = installedfontcollection.Families;

            //在窗体上显示系统中已安装的字体信息
            int index = 0;
            foreach (FontFamily i in fontfamilies)
            {
                tmp += i.Name + ",";
                index++;
            }

            Rectangle r = new Rectangle(0, 10, this.Width, this.Height);
            graphics.DrawString(tmp, font, solidbrush, r, fmt);
            tmp = string.Format("在你系统中已安装的字体有{0}种,其名称分别为:/n", index + 1);
            graphics.DrawString(tmp, font, solidbrush, new Point(0, 0));
        } 

你可能感兴趣的:(string)