日期:2014-05-18  浏览次数:20918 次

用C#写的历史信息菜单,VS2008调试时候窗口都不显示?
public partial class Form1 : Form
  {
  public string address = @"D:\课程\练习\WindowsFormsApplication12";
  public Form1()
  {
  InitializeComponent();
  }

  private void toolStripMenuItem1_Click(object sender, EventArgs e)
  {
  openFileDialog1.FileName = "";
  this.openFileDialog1.ShowDialog();
  StreamWriter s = new StreamWriter(address + "\\Menu.ini", true);
  s.WriteLine(openFileDialog1.FileName);
  s.Flush();
  s.Close();
  ShowWindows(openFileDialog1.FileName);
  }
  public void ShowWindows(string fileName)
  {
  Image p = Image.FromFile(fileName);
  Form f = new Form();
  f.MdiParent = this;
  f.BackgroundImage = p;
  f.Show();
  }

  private void Form1_Load(object sender, EventArgs e)
  {
  StreamReader sr = new StreamReader(address + "Menu.ini");
  int i = this.toolStripMenuItem1.DropDownItems.Count - 2;
  while (sr.Peek() > 0)
  {
  ToolStripMenuItem menuitem = new ToolStripMenuItem(sr.ReadLine());
  this.toolStripMenuItem1.DropDownItems.Insert(i, menuitem);
  i++;
  menuitem.Click += new EventHandler(menuitem_Click);
  }
  sr.Close();
  }
  public void menuitem_Click(object sender, EventArgs e)
  {
  if (sender is ToolStripMenuItem)
  {
  ShowWindows(((ToolStripMenuItem)sender).Text);
  }
  }

  }


------解决方案--------------------
StreamReader sr = new StreamReader(address + "Menu.ini");
=>
StreamReader sr = new StreamReader(address + "\\Menu.ini");