程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> c#4.0-錯誤 1 當前上下文中不存在名稱“menuitem_Click 代碼如下

c#4.0-錯誤 1 當前上下文中不存在名稱“menuitem_Click 代碼如下

編輯:編程綜合問答
錯誤 1 當前上下文中不存在名稱“menuitem_Click 代碼如下

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 MenuHistory
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
string address = System.Environment.CurrentDirectory;
}

    private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
    {

    }

    private void 打開ToolStripMenuItem_Click(object sender, EventArgs e)
    {
        openFileDialog1.FileName = "";
        this.openFileDialog1.ShowDialog();
        StreamWriter s = new StreamWriter("Menu.ini", true);
        s.WriteLine(openFileDialog1.FileName);
        s.Flush();
        s.Close();
        ShowWindows(openFileDialog1.FileName);
    }

    private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs 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 Form1_Load(object sender, EventArgs e)
    {
        if (File.Exists("Menu.ini"))
        {
            StreamReader sr = new StreamReader("Menu.ini");
            int i = this.文件ToolStripMenuItem.DropDownItems.Count;
            while (sr.Peek() >= 0)
            {
                ToolStripMenuItem menuitem = new ToolStripMenuItem();
                this.文件ToolStripMenuItem.DropDownItems.Insert(i, menuitem);
                i++;
                menuitem.Click += new EventHandler(menuitem_Click); 
            }
            sr.Close();
        }
    }

    private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
    {
        Application.Exit();
    }

    private void 關閉所有ToolStripMenuItem_Click(object sender, EventArgs e)
    {
        foreach (Form frm in this.MdiChildren) 
        {
            frm.Close(); //關閉子窗體
        }
    }
}

}

最佳回答:


你說的那個東西代碼裡沒有

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved