| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 594 人关注过本帖
标题:C#带历史记录的菜单
取消只看楼主 加入收藏
uighurlar
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2012-10-6
结帖率:0
收藏
已结贴  问题点数:20 回复次数:0 
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个历史记录。
谢了~。。。。
搜索更多相关主题的帖子: 历史记录 address private void 菜单 
2012-10-06 12:56
快速回复:C#带历史记录的菜单
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016777 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved