//将文件内容读取然后显示到列表上
ClearTree();
StreamReader sr = new StreamReader(localpath, Encoding.Default);
String line;
while ((line = sr.ReadLine()) != null)
{
if (line != "")
{
SetList(line);
}
}
sr.Close();
private void SetList(string rserver)
{
Boolean isAdd = false;
string[] src = rserver.Split('|');
try
{
if (src.Length > 4)
{
if (this.treeView1.InvokeRequired == true)
{
InvokeCallback d = new InvokeCallback(SetList);
this.Invoke(d, new object[] { rserver });
}
else
{
for (int j = 0; j < this.treeView1.Nodes.Count; j++)
{
if (treeView1.Nodes[j].Text == src[0])
{
isAdd = true;
TreeNode node = treeView1.Nodes[j];
node.Nodes.Add(src[1]);
ServerName[nowNum] = src[1];
ServerIp[nowNum] = src[3];
ServerPort[nowNum] = Convert.ToInt32(src[4]);
nowNum++;
break;
}
}
if (isAdd == false)
{
treeView1.Nodes.Add(src[0]);
TreeNode node = treeView1.Nodes[treeView1.Nodes.Count - 1];
node.Nodes.Add(src[1]);
ServerName[nowNum] = src[1];
ServerIp[nowNum] = src[3];
ServerPort[nowNum] = Convert.ToInt32(src[4]);
nowNum++;
}
}
}
}
catch (Exception ex)
{
MessageBox.Show("意外错误!!!" + ex.Message); ;
}
}