using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace Ex01_01
{
public partial class Form1 : Form
{
string address;
public Form1()
{
InitializeComponent();
address = System.Environment.CurrentDirectory;//获取当前环境和工作台的目录
}
private void Form1_Load(object sender, EventArgs e)
{
StreamWriter s = new StreamWriter(address + "\\Menu.ini", true);//在当前目录下创建一个Menu.ini配置文件
s.Close();
StreamReader sr = new StreamReader(address + "\\Menu.ini");
int i = this.文件ToolStripMenuItem.DropDownItems.Count - 2;
while (sr.Peek() >= 0)//读取INI文件
{
ToolStripMenuItem menuitem = new ToolStripMenuItem(sr.ReadLine());
this.文件ToolStripMenuItem.DropDownItems.Insert(i, menuitem);
menuitem.Click += new EventHandler(menuitem_Click);
}
sr.Close();
}
private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
{
openFileDialog1.FileName = "";
this.openFileDialog1.ShowDialog();
StreamWriter s = new StreamWriter(address + "\\Menu.ini", true);//在当前目录下创建一个Menu.ini配置文件
s.WriteLine(openFileDialog1.FileName);//写入INI文件
s.Flush();
s.Close();
ShowWindows(openFileDialog1.FileName);
}
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();
}
private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace Ex01_01
{
public partial class Form1 : Form
{
string address;
public Form1()
{
InitializeComponent();
address = System.Environment.CurrentDirectory;//获取当前环境和工作台的目录
}
private void Form1_Load(object sender, EventArgs e)
{
StreamWriter s = new StreamWriter(address + "\\Menu.ini", true);//在当前目录下创建一个Menu.ini配置文件
s.Close();
StreamReader sr = new StreamReader(address + "\\Menu.ini");
int i = this.文件ToolStripMenuItem.DropDownItems.Count - 2;
while (sr.Peek() >= 0)//读取INI文件
{
ToolStripMenuItem menuitem = new ToolStripMenuItem(sr.ReadLine());
this.文件ToolStripMenuItem.DropDownItems.Insert(i, menuitem);
menuitem.Click += new EventHandler(menuitem_Click);
}
sr.Close();
}
private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
{
openFileDialog1.FileName = "";
this.openFileDialog1.ShowDialog();
StreamWriter s = new StreamWriter(address + "\\Menu.ini", true);//在当前目录下创建一个Menu.ini配置文件
s.WriteLine(openFileDialog1.FileName);//写入INI文件
s.Flush();
s.Close();
ShowWindows(openFileDialog1.FileName);
}
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();
}
private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}