zoukankan      html  css  js  c++  java
  • 显示系统所有字体

    本实例创建一个能显示系统已安装的字体的程序,并将字体信息显示在RichTextBox中,程序运行结果如下图。

    20120409163115

    程序代码如下。

    using System;
    using System.Drawing;
    using System.Drawing.Text;
    using System.Windows.Forms;
    namespace eg48_displayFont
    {
    	public partial class MainForm : Form
    	{
    		public MainForm()
    		{
    			InitializeComponent();
    		}
    		
    		void B_DisplayFontsClick(object sender, EventArgs e)
    		{
    			InstalledFontCollection ifc=new InstalledFontCollection();
    			FontFamily[] ffs=ifc.Families;
    			Font f;
    			richTextBox1.Clear();
    			foreach(FontFamily ff in ffs)
    			{
    				if(ff.IsStyleAvailable(System.Drawing.FontStyle.Regular))
    					f=new Font(ff.GetName(1),12,System.Drawing.FontStyle.Regular);
    				else if(ff.IsStyleAvailable(System.Drawing.FontStyle.Bold))
    					f=new Font(ff.GetName(1),12,System.Drawing.FontStyle.Bold);
    				else if(ff.IsStyleAvailable(System.Drawing.FontStyle.Italic))
    					f=new Font(ff.GetName(1),12,System.Drawing.FontStyle.Italic);
    				else
    					f=new Font(ff.GetName(1),12,System.Drawing.FontStyle.Underline);
    				richTextBox1.SelectionFont=f;
    				richTextBox1.AppendText(ff.GetName(1)+"\r\n");
    				richTextBox1.SelectionFont=f;
    				richTextBox1.AppendText("abcdefghijklmnopqrstuvwxyz\r\n");
    				richTextBox1.SelectionFont=f;
    				richTextBox1.AppendText("ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n");
    				richTextBox1.AppendText("==========================\r\n");
    			}
    			MessageBox.Show("已经把所有字体显示在文本框中","成功",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
    		}
    	}
    }
    作者:codee
    文章千古事,得失寸心知。


  • 相关阅读:
    封装、权限修饰符、包、构造器
    从Discuz!NT v2.0扣出来的生成静态页面的方法
    C#中struct与class的区别
    Asp.Net中虚拟文件系统的使用
    C#生成中文验证码
    C#导入Excel表
    IIS5、IIS6、IIS7的ASP.net 请求处理过程比较
    如何保证Session值不丢失
    C#抽象类与接口的区别
    C#实现DES加密解密
  • 原文地址:https://www.cnblogs.com/bimgoo/p/2437735.html
Copyright © 2011-2022 走看看