private void OpenLove() { FrmMyLove love = new FrmMyLove(this); love.Show(); }
/// <summary> /// 传入要打开的文件路径,同时可选传入收藏信息窗体,便于刷新窗体信息 /// </summary> /// <param name="path"></param> /// <param name="love"></param> public void OpenFile(string path, FrmMyLove frmLove = null) { //如果是txt直接显示,world或其他用运行打开 if (path.Substring(path.Length - 3, 3) == "txt") { //直接显示到文本框里 if (File.Exists(path)) { this.txtContent.Text = ""; StreamReader reader = null; try { this.txtContent.Tag = path; reader = new StreamReader(path, Encoding.GetEncoding(encoding)); StringBuilder fileContent = new StringBuilder(); string temp = ""; while ((temp = reader.ReadLine()) != null) { fileContent.AppendLine(temp); } this.txtContent.Text = fileContent.ToString(); beforeContent = fileContent.ToString(); } catch (Exception ie) { MessageBox.Show("发生错误!错误信息:\n" + ie.Message); } finally { if (reader != null) { reader.Close(); } } lblMode.ForeColor = Color.Black; lblMode.Text = "加载完成"; this.Text = "乐智知识库 - [" + path + "]"; } else { lblMode.ForeColor = Color.Red; lblMode.Text = "文件不存在!"; XmlDocument doc = new XmlDocument(); doc.Load("love.xml"); XmlElement root = doc.DocumentElement; foreach (XmlNode item in root.GetElementsByTagName("love")) { if (item.LastChild.InnerText.Equals(path)) { root.RemoveChild(item); doc.Save("love.xml"); if (frmLove != null) { frmLove.BingData(); } MessageBox.Show("从收藏列表中已经移除", "收藏的文件不存在", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } } } else { //用自动的关联程序打开 Process.Start(path); } }