C#中如何获取字体类型,颜色,和大小.
来源:互联网 发布:网络主播文儿的歌曲 编辑:程序博客网 时间:2024/04/19 15:11
using System;
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.Parse(this.txtSize.Text)); //设置字体的大小
}
}
}
转自:http://blog.myspace.cn/e/402912960.htm
- C#中如何获取字体类型,颜色,和大小.
- c#如何获取当前系统所有的字体和颜色?
- 关于如何修改PreferenceFragment中默认的字体颜色和大小
- Dreamweaver中如何设定文字——大小、字体、颜色
- UILabel字体颜色和大小
- 改变vs2005中代码字体的大小和颜色
- SpannableString 动态设置textView中字体颜色和大小
- UITextField中放置UIImage 和placeholder 字体、颜色、大小、位置
- 如何改变CEdit的字体颜色大小
- 如何改变CEdit的字体颜色大小
- Linux 终端如何改变字体 大小 颜色
- MFC修改按钮中字体颜色大小
- 修改UIWebView中字体的大小,颜色
- C# 中字体和颜色的XML序列化
- putty修改字体颜色和大小
- 改变字体的颜色和大小
- android spinner 修改字体颜色和大小
- AndroidStudio更改字体颜色和大小
- STM32 定时器浅谈_1
- Java设计模式研究之策略模式
- UVA11987- Almost Union-Find
- struts2+jqury ajax问题汇总与解决办法
- 3.线性表的应用-一元多项式的计算
- C#中如何获取字体类型,颜色,和大小.
- 异常:System.IO.FileNotFoundException: 未能加载文件或程序集“Microsoft.mshtml
- ios申请真机调试( xcode 5)详细解析
- 2014 第十一届浙江省程序设计竞赛
- Cocos2x 适配
- 多线程__下
- java枚举一个目录下的所有文件的问题
- POJ1006
- 安卓 再按一次退出