一个能查看历史信息的菜单遇到的问题
在网上得到一个能够实现在菜单栏中查看历史信息的代码,自己修改了一下,在运行时遇到错误 错误 1 当前上下文中不存在名称“menuitem_Click” E:\C#Practice\Ex01_01\Ex01_01\Form1.cs 53 52 Ex01_01
程序代码:using System;
using System.Collections.Generic;
using using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using namespace Ex01_01
{
public partial class Form1 : Form
{
public string address = @"E:\C#Practice\Ex01_01";
public Form1()
{
InitializeComponent();
}
//自定义方法ShowWindows()用来家在背景图片应显示窗体
public void ShowWindows(string fileName)
{
Image p = Image.FromFile(fileName);
Form f = new Form();
f.MdiParent = this;
f.BackgroundImage = p;
f.Show();
}
//将打开文件路径写入INI文件中
private void 打开ToolStripMenuItem_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);
}
//读取INI文件并将信息加入菜单
private void Form1_Load(object sender, EventArgs e)
{
StreamReader sr=new StreamReader(address+"\\Menu.ini");
int i=this.文件ToolStripMenuItem.DropDownItems.Count-2;
while(sr.Peek()>=0)
{
ToolStripMenuItem menuitem=new ToolStripMenuItem(sr.ReadLine());
this.文件ToolStripMenuItem.DropDownItems.Insert(i,menuitem);
i++;
menuitem.Click += new EventHandler(menuitem_Click);
}
sr.Close();
}
}
}




受益匪浅,谢谢老师!