这个应该很简单吧,你直接在绑定ListView数据项的时候将第一行设置其前景色或后景色。
成都创新互联专注于墨玉网站建设服务及定制,我们拥有丰富的企业做网站经验。 热诚为您提供墨玉营销型网站建设,墨玉网站制作、墨玉网页设计、墨玉网站官网定制、小程序开发服务,打造墨玉网络公司原创品牌,更为您提供墨玉网站排名全网营销落地服务。
private void LoadMockData()
{
listView1.Items.Clear();
var users = new ListUser {
new User { Id = 1, Name = "Jim", Age = 22, Sex = "Male" },
new User { Id = 2, Name = "Tom", Age = 21, Sex = "Male" },
new User { Id = 3, Name = "Henry", Age = 23, Sex = "Male" },
new User { Id = 4, Name = "Rah", Age = 24, Sex = "Male" },
new User { Id = 5, Name = "Ram", Age = 22, Sex = "Female" },
new User { Id = 6, Name = "Loha", Age = 25, Sex = "Male" }
};
int i = 1;
foreach (User user in users)
{
ListViewItem item = new ListViewItem();
item.SubItems.Clear();
item.Text = user.Id.ToString();
item.SubItems.Add(user.Name);
item.SubItems.Add(user.Age.ToString());
item.SubItems.Add(user.Sex);
if (i == 1)
{
item.BackColor = Color.Aqua;
item.ForeColor = Color.Red;
}
listView1.Items.Add(item);
i++;
}
}
效果图如下:
public Color col(string colorName)
{
Type colorType = typeof(Color);
PropertyInfo info = colorType.GetProperty(colorName, BindingFlags.Public | BindingFlags.Static);
if (infos == null)
{
//throw Exception
}
return(Color)info.GetValue(null, null);
}
是这个意思么?输入“Red”, 返回Color.Red 区分大小写
你好,我不知道你是用什么方法保存的,不过.net里的color有一个方法是Color.FromArgb 你可以这么做,dim
c
as
color=richtextbox1.ForeColor dim
colorstring
as
string=c.ToArgb().ToString
colorstring就是颜色的值(字符串)再把colorstring保存到ini文件加载颜色的时候,从ini里读取colorstring 具体是:dim
RtextColor
as
color=Color.FromArgb(cint(colorstring))richtextbox1.ForeColor
=RtextColor