c#遍歷System.drawing.Color下面的所有顏色以及名稱以查看
更新時間:2013年02月22日 09:24:37 作者:
c#遍歷System.drawing.Color下面的所有顏色以及名稱以查看,需要的朋友可以參考一下
面試的時候被問到,如何遍歷System.drawing.Color下面的所有顏色以及名稱以查看,當(dāng)時答得不好,現(xiàn)將方案記錄如下:
復(fù)制代碼 代碼如下:
View Code
public partial class Form1 : Form
{
FlowLayoutPanel newPanel = new FlowLayoutPanel();
public Form1()
{
InitializeComponent();
newPanel.AutoScroll = true;
//newPanel.FlowDirection = FlowDirection.BottomUp;
//newPanel.WrapContents = false;
newPanel.Dock = DockStyle.Fill;
newPanel.BackColor = Color.White;
button1.Anchor = (AnchorStyles.Bottom | AnchorStyles.Right);
}
private void button1_Click(object sender, EventArgs e)
{
newPanel.Controls.Clear();
int i = 1;
foreach (var item in typeof(Color).GetMembers())
{
if (item.MemberType == System.Reflection.MemberTypes.Property && System.Drawing.Color.FromName(item.Name).IsKnownColor == true)//只取屬性且為屬性中的已知Color,剔除byte屬性以及一些布爾屬性等(A B G R IsKnownColor Name等)
{
Label myLable = new Label();
myLable.AutoSize = true;
myLable.BackColor = System.Drawing.Color.FromName(item.Name);
myLable.Text = System.Drawing.Color.FromName(item.Name).Name;
newPanel.Controls.Add(myLable);
//newPanel.GetFlowBreak(myLable);
i++;
}
}
this.Controls.Add(newPanel);
button1.Text = i.ToString();
}
}
相關(guān)文章
解析美國東部時間與北京時間相互轉(zhuǎn)換的實現(xiàn)代碼
本篇文章是對美國東部時間與北京時間相互轉(zhuǎn)換的實現(xiàn)代碼進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-05-05C#實現(xiàn)集合轉(zhuǎn)換成json格式數(shù)據(jù)的方法
這篇文章主要介紹了C#實現(xiàn)集合轉(zhuǎn)換成json格式數(shù)據(jù)的方法,涉及C#針對dataTable、Enumerable及Json格式數(shù)據(jù)的遍歷及轉(zhuǎn)換操作相關(guān)技巧,需要的朋友可以參考下2016-07-07