C#中如何取得系统字体

本文介绍了如何使用C#在ASP.NET应用程序中获取系统安装的所有字体,并列出这些字体的名称及样式选项。通过实例代码展示了如何填充两个下拉列表:一个用于显示所有可用的字体家族名称,另一个用于展示字体的各种样式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

系统字体列表 
系统字体样式 
   
protected System.Web.UI.WebControls.DropDownList DropDownList2;
protected System.Web.UI.WebControls.DropDownList DropDownList1;

private void Page_Load(object sender, System.EventArgs e)      
{      
     //如何获得系统字体列表         
      System.Drawing.Text.InstalledFontCollection fonts = new System.Drawing.Text.InstalledFontCollection();            
     foreach (System.Drawing.FontFamily family in fonts.Families) 
     {                 
          DropDownList1.Items.Add(family.Name); 
     }
     //如何获得系统字体样式
      ArrayList list=new ArrayList();
     foreach(int i in Enum.GetValues(typeof(System.Drawing.FontStyle)))
     {
           ListItem listitem = new ListItem(Enum.GetName(typeof(System.Drawing.FontStyle),i),i.ToString());
           list.Add(listitem);
     }
     DropDownList2.Items.Clear();
     DropDownList2.DataSource=list;
     DropDownList2.DataValueField="value";
     DropDownList2.DataTextField="text";
     DropDownList2.DataBind();
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值