hong34210
hong34210
2015-04-19 08:41
采纳率: 97%
浏览 1.8k

动态创建Menu c# ado.net

想动态创建menustrip,下面的代码在form里有用,但是在copy到cs里面却报了4个错, this.Hide();, this.SuspendLayout();, this.Controls.Add(this.menuStrip1);, this.ResumeLayout(false);

``` private void 工序录入ToolStripMenuItem_Click(object sender, EventArgs e)
{
工序资料维护 frmGXLR = new 工序资料维护();
frmGXLR.Show();
this.Hide();

    }

    private void 录入ToolStripMenuItem1_Click(object sender, EventArgs e)
    {
        中小修管理录入 frmZXXGLLR = new 中小修管理录入();
        frmZXXGLLR.Show();
        this.Hide();
    }
    //动态创建menuSctrip
    private void addMenuSctrip()
    {
             this.menuStrip1 = new System.Windows.Forms.MenuStrip();
        this.文件ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
                        this.menuStrip1.SuspendLayout();
        this.SuspendLayout();
        // 
        // menuStrip1
        // 
        this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
        this.文件ToolStripMenuItem,
        this.menuStrip1.Location = new System.Drawing.Point(0, 0);
        this.menuStrip1.Name = "menuStrip1";
        this.menuStrip1.Size = new System.Drawing.Size(284, 25);
        this.menuStrip1.TabIndex = 40;
        this.menuStrip1.Text = "menuStrip1";
        // 
                            // 
        // 文件ToolStripMenuItem
        // 
        this.文件ToolStripMenuItem.Name = "文件ToolStripMenuItem";
        this.文件ToolStripMenuItem.Size = new System.Drawing.Size(44, 21);
        this.文件ToolStripMenuItem.Text = "文件"; 
                    this.Controls.Add(this.menuStrip1);
        this.menuStrip1.ResumeLayout(false);
        this.menuStrip1.PerformLayout();
        this.ResumeLayout(false);
            }
             private System.Windows.Forms.MenuStrip menuStrip1;
    private System.Windows.Forms.ToolStripMenuItem 文件ToolStripMenuItem;

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • caozhy
    已采纳

    放在cs中,给你的每个函数增加一个参数,比如
    private void addMenuSctrip()
    ->
    private void addMenuSctrip(你的窗体类型 frm)
    然后,所有用到
    this.Hide();
    等地方,都把this换成frm
    frm.Hide();

    点赞 评论
  • happy09li
    熙风 2015-04-20 04:15

    ToolStripMenuItem menuItem=new ToolStripMenuItem();
    ToolStripMenuItem menuSubItem = new ToolStripMenuItem("");
    menuSubItem.Name =""
    menuSubItem.Click += new EventHandler(menuSubItem_Click);
    menuItem.DropDownItems.Add(menuSubItem);

    点赞 评论

相关推荐