C#中如何获取字体类型,颜⾊,和⼤⼩. using System;typeof array
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Font : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//获取系统的所有字体名称(⽅法⼀)
//for (int i = 0; i < = System.Drawing.FontFamily.Families.Length - 1; i++)
//{
//      this.ddlFont.Items.Add(System.Drawing.FontFamily.Families[i].Name);
//}
//获取系统的所有字体名称,也可以使⽤foreach(⽅法⼆)
System.Drawing.Text.InstalledFontCollection font; //安装在系统的所有字体,⽆法继承
font = new System.Drawing.Text.InstalledFontCollection();
foreach (System.Drawing.FontFamily family in font.Families)
{
this.ddlFont .Items.Add(family.Name);
}
//获取系统所有颜⾊(利⽤枚举获取系统的颜⾊并且将Dropdownlist的字体颜⾊改成当前的颜⾊)
string[] colorArray = Enum.GetNames(typeof(System.Drawing.KnownColor));
foreach (string color in colorArray)
{
ListItem item = new ListItem(color);
item.Attributes.Add(" style" , " color:" + color);
this.ddlColor .Style.Add(" BackColor" , color);
this.ddlColor .Items.Add(item);
}
//系统字体⼤⼩
string[] sizeArray = Enum.GetNames(typeof(System.Web.UI.WebControls.FontSize));
this.rblSize .DataSource = sizeArray;
this.rblSize.SelectedIndex = -1;
this.rblSize.DataBind();
}
protected void btnFont_Click(object sender, EventArgs e)
{
this.lblString.ForeColor = System.Drawing.Color.FromName(this.ddlColor.SelectedItem.Text);
this.lblString.Font.Name = this.ddlFont.SelectedItem.Text;
if (this.rblSize.SelectedIndex > -1)
{
this.lblString.Font.Size = FontUnit.Parse(this.rblSize.SelectedItem.Text); //选择字体的⼤⼩        }
else
{
this.lblString.Font.Size = FontUnit.Point(Int32.Size.Text)); //设置字体的⼤⼩        }
}
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。