C#带历史记录的菜单
一下为源代码:using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using
namespace Ex01_01
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string address = System.Environment.CurrentDirectory;
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);
}
private void menuitem_Click(object sender, EventArgs e)
{
StreamReader sr = new StreamReader(address + "\\Menu.ini");
Image p = Image.FromFile(sr.ReadLine());
Form f = new Form();
f.MdiParent = this;
f.BackgroundImage = p;
f.BackgroundImageLayout = ImageLayout.Zoom;
f.Show();
}
public void ShowWindows(string fileName)
{
Image p = Image.FromFile(fileName);
Form f = new Form();
f.MdiParent = this;
f.BackgroundImage = p;
f.BackgroundImageLayout = ImageLayout.Zoom;
f.Show();
}
private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}
private void 关闭所有ToolStripMenuItem_Click(object sender, EventArgs e)
{
}
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();
}
}
}
这个代码没有问题,不过随着历史记录的增多,菜单里的记录也增多。我想请教各位高手,怎么实现,不记录“相同历史记录”,而且历史记录数超过10条了,就删掉前面的记录,保持菜单里面是最近最新的10个历史记录。
谢了~。。。。