【发布时间】:2012-10-17 14:29:30
【问题描述】:
在表格的顶部我有:
string[] data;
Color []color;
在构造函数中:
color = new Color[1] { Color.Red};
然后我在构造函数中加载了一个函数:
private void ListBoxLoadKeys(Dictionary<string,List<string>> dictionary,
string FileName)
{
string line = System.String.Empty;
using (StreamReader sr = new StreamReader(keywords))
{
while ((line = sr.ReadLine()) != null)
{
int i = line.Count();
tokens = line.Split(',');
dictionary.Add(tokens[0], tokens.Skip(1).ToList());
// listBox1.Items.Add("Url: " + tokens[0] + " --- "
+ "Localy KeyWord: " + tokens[1]);
data = new string[1] { "Url: " + tokens[0] + " --- "
+ "Localy KeyWord: " + tokens[1]};
listBox1.DataSource = data;
}
}
}
但它只添加到 ListBox 一行中。 我希望它像 listbox1.Items.Add 然后将文本文件中的所有行添加到 listBox。
然后我将线条涂成红色:
private void listBox1_DrawItem(object sender, DrawItemEventArgs e)
{
e.DrawFocusRectangle();
e.Graphics.DrawString(data[e.Index], new Font(FontFamily.GenericSansSerif, 8,
FontStyle.Regular),new SolidBrush(color[e.Index]), e.Bounds);
}
private void listBox1_MeasureItem(object sender, MeasureItemEventArgs e)
{
e.ItemHeight = 16;
}
如何添加 StreamReader 中的所有行,而不是使用 Items.Add 但使用 DataSource ?
-
我怎样才能只用“Url:”这个词用红色着色我有这一行:
data = new string[1] { "Url: " + tokens[0] + " --- " + "Localy KeyWord: " + tokens[1]};
我希望它添加文本文件中的所有行,并且每行只为单词“Url:”着色
【问题讨论】: