欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#讀取系統(tǒng)字體顏色與大小的方法

 更新時(shí)間:2015年06月09日 17:02:57   作者:McJeremy&Fan  
這篇文章主要介紹了C#讀取系統(tǒng)字體顏色與大小的方法,較為詳細(xì)的分析了C#獲取系統(tǒng)字體顏色與大小的相關(guān)技巧,需要的朋友可以參考下

本文實(shí)例講述了C#讀取系統(tǒng)字體顏色與大小的方法。分享給大家供大家參考。具體分析如下:

首先,說到字體、顏色,我們應(yīng)該想到System.Drawing命名空間

先說說獲取系統(tǒng)字體的方法:

在System.Drawing命名空間下有個FontFamily類,其下有個靜態(tài)屬性:Families(返回的是一個 FontFamily對象數(shù)組)

注:System.Drawsing.FontFamily是一個密封類。

而在System.Drawing.Text命名空間下有個InstalledFontCollection類,其下也有個屬性:Families,不過此時(shí)不是靜態(tài)屬性。

注:System.Drawing.InstalledFontCollection也是一個密封類。

現(xiàn)在分別用這兩個東東來獲取一下:

FontFamily獲?。?/strong>

//前臺有個familyList(DropDownList控件)
for(int i=0;i<FontFamily.Families.Length;i++)
{
  familyList.Items.Add(FontFamily.Families[i].Name);
}

第一種方法簡單吧。

第二種方法:InstalledFontCollection

InstalledFontCollection ifc=new InstalledFontCollection();
foreach(FontFamily ff in ifc.Families)
{
 familyList2.Items.Add(ff.Name);
}

這個也簡單 ^_^

獲取系統(tǒng)已安裝的顏色:

打開MSDN,你會發(fā)現(xiàn),System.Drawing下有個KnownColor的枚舉,其中就列出了N多顏色值哦,現(xiàn)在我們把它讀出來~~

//System.Drawing.KnownColor
string[] colors=Enum.GetNames(typeof(System.Drawing.KnownColor);
foreach(string color in colors)
{ 
 ListItem list=new ListItem(color);
 list.Attributes.Add("style","color:"+color);
 colorList.Items.Add(list);
}

獲取字體大小:

字體大小應(yīng)該也和顏色一樣有個枚舉存儲。但此時(shí),它卻在System.Web.UI.WebControls下了,大名叫:FontSize

代碼如下:

//System.Web.UI.WebControls.FontSize
string[] sizes=Enum.GetName(typeof(System.Web.UI.WebControls.FontSize));
foreach(string size in sizes)
{
 sizeList.Items.Add(size);
}

隨便提一下:Enum.GetNames(Type)返回的是一個字體串?dāng)?shù)組,而Enum.GetValues(Type)返回的是Array對象。

希望本文所述對大家的C#程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評論