主题:关于带历史信息的菜单
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace 带历史信息的菜单
{
public partial class Form1 : Form
{
string adress;
public Form1()
{
InitializeComponent();
adress = System.Environment.CurrentDirectory;//设定当前目录下的完全限定地址
}
private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
{
openFileDialog1.FileName = "";
this.openFileDialog1.ShowDialog();
StreamWriter sw = new StreamWriter(adress + "\\Menu.ini", true);
sw.WriteLine(openFileDialog1.FileName);
sw.Flush();
sw.Close();
//this.axWindowsMediaPlayer1.URL = this.openFileDialog1.FileName;
//this.axWindowsMediaPlayer1.Show();
showWindows(openFileDialog1.FileName);
}
private void Form1_Load(object sender, EventArgs e)
{
StreamReader sr = new StreamReader(adress + "\\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();
}
}
private void menuitem_Click(object sender, EventArgs e)
{
ToolStripMenuItem menu = (ToolStripMenuItem)sender;
showWindows(menu.Text);
}
public void showWindows(string fileName)
{
Image p = Image.FromFile(fileName);
Form f = new Form();
f.MdiParent = this;
f.BackgroundImage = p;
f.Show();
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace 带历史信息的菜单
{
public partial class Form1 : Form
{
string adress;
public Form1()
{
InitializeComponent();
adress = System.Environment.CurrentDirectory;//设定当前目录下的完全限定地址
}
private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
{
openFileDialog1.FileName = "";
this.openFileDialog1.ShowDialog();
StreamWriter sw = new StreamWriter(adress + "\\Menu.ini", true);
sw.WriteLine(openFileDialog1.FileName);
sw.Flush();
sw.Close();
//this.axWindowsMediaPlayer1.URL = this.openFileDialog1.FileName;
//this.axWindowsMediaPlayer1.Show();
showWindows(openFileDialog1.FileName);
}
private void Form1_Load(object sender, EventArgs e)
{
StreamReader sr = new StreamReader(adress + "\\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();
}
}
private void menuitem_Click(object sender, EventArgs e)
{
ToolStripMenuItem menu = (ToolStripMenuItem)sender;
showWindows(menu.Text);
}
public void showWindows(string fileName)
{
Image p = Image.FromFile(fileName);
Form f = new Form();
f.MdiParent = this;
f.BackgroundImage = p;
f.Show();
}
}
}