using System;
using System.Windows.Forms;
using System.Collections;
using System.IO;
namespace SDA_0183_imd_02
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private Hashtable g = new Hashtable();
private void Form1_Load(object sender, System.EventArgs e)
{
BuildGlossary(g);
DisplayWords(g);
lbWord.SelectedIndex = 0;
Object word;
word = lbWord.SelectedItem;
richTextBox1.Text = g[word].ToString();
}
private void BuildGlossary(Hashtable g)
{
StreamReader inFile;
string line;
string[] words;
inFile = File.OpenText("d.txt");
char[] delimiter = new char[] { '#' };
while (inFile.Peek() != -1)
{
line = inFile.ReadLine();
words = line.Split(delimiter);
g.Add(words[0], words[1]);
}
inFile.Close();
}
private void DisplayWords(Hashtable g)
{
Object[] words = new Object[g.Count];
g.Keys.CopyTo(words, 0);
for (int i = 0; i <= words.GetUpperBound(0); i++)
if (!(words[i] == null))
lbWord.Items.Add((words[i]));
}
private void clearing(Hashtable g)
{
g.Clear();
}
private void lbWord_SelectedIndexChanged(object sender, System.EventArgs e)
{
Object word;
word = lbWord.SelectedItem;
richTextBox1.Text = g[word].ToString();
}
}
}
我应该填写一个richTextBox,但是表中没有填写我创建的文件中的信息。 该文件包含一些字典条目,但不显示条目。 我不确定设置中的某些内容是否正确并且我错过了,所以任何输入都非常感激。