111,098
社区成员




//绑定下拉框数据
public static void BindCom(RichTextBox txt,ComboBox com, string path)
{
//RichTextBox txt = new RichTextBox(); ← 注意这实例化
string[] typeBooks;
if (!File.Exists(path))
{
typeBooks = new string[]{"选择类型","type0","type1",
"type2","type3","type4","type5","type6"};
int count = typeBooks.Count();
int len = 1;
foreach (var str in typeBooks)
{
txt.Text += str;
if (len < typeBooks.Count())
{ txt.Text += "\n"; len++; }
}
txt.SaveFile(path, RichTextBoxStreamType.PlainText);
}
FileStream fs = new FileStream(path,
FileMode.Open, FileAccess.Read, FileShare.None);
StreamReader sr = new StreamReader(fs, Encoding.Default);
txt.Text = sr.ReadToEnd();
sr.Close();
sr.Dispose();
typeBooks = txt.Lines;
foreach (var str in typeBooks)
{
if (str != "")
com.Items.Add(str);
}
com.SelectedIndex = 0;
}
private void button1_Click(object sender, EventArgs e)
{
//typeBooks = new string[]{"选择类型","type0","type1",
// "type2","type3","type4","type5","type6"};
//int count = typeBooks.Count();
//int len = 1;
//foreach (var str in typeBooks)
//{
// richTextBox1.Text += str;
// if (len < typeBooks.Count())
// { richTextBox1.Text += "\n"; len++; }
//}
//richTextBox1.SaveFile("Type.txt", RichTextBoxStreamType.TextTextOleObjs);
BindCom(richTextBox1 ,comboBox1, "Type.txt");
}