C# 如何向menuStrip中加入菜单
我的menustrip中有几个菜单.我要在某一个菜单的下面写代码加一个怎么做,请各人高人说说...在原来有的下面再加一个,不是加一个新的菜单选项....
我的menustrip中有几个菜单.我要在某一个菜单的下面写代码加一个怎么做,请各人高人说说...
在原来有的下面再加一个,不是加一个新的菜单选项. 展开
在原来有的下面再加一个,不是加一个新的菜单选项. 展开
展开全部
private void button1_Click(object sender, EventArgs e)
{
ToolStripMenuItem tsmi = new ToolStripMenuItem();
tsmi.Text = "123";
menuStrip1.Items.Add(tsmi);
}
添加一个菜单选项
这是最简单的,如果需要动态的加,可以根据数据库来
补充:如果是在原有的下面在加一个
就是menuStrip1.selecteditem.childitem.add()
这句代码是随便写的,可以找到类似的
如果还不行,站内消息我
{
ToolStripMenuItem tsmi = new ToolStripMenuItem();
tsmi.Text = "123";
menuStrip1.Items.Add(tsmi);
}
添加一个菜单选项
这是最简单的,如果需要动态的加,可以根据数据库来
补充:如果是在原有的下面在加一个
就是menuStrip1.selecteditem.childitem.add()
这句代码是随便写的,可以找到类似的
如果还不行,站内消息我
展开全部
winfrom 的menuStrip在你所添加的菜单像双击,就进入了menuStrip所选的单击事件。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
先在设计器里手动添加,然后在Designer.cs里找到相应代码剪切过来,就可以实现
menuStrip中加入菜单
如下:
private System.Windows.Forms.MenuStrip menuStrip1;
private System.Windows.Forms.ToolStripMenuItem aAAToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem bBBToolStripMenuItem;
private void button1_Click(object sender, EventArgs e)
{
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.aAAToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.bBBToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
//
// menuStrip1
//
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.aAAToolStripMenuItem});
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(524, 24);
this.menuStrip1.TabIndex = 3;
this.menuStrip1.Text = "menuStrip1";
//
// aAAToolStripMenuItem
//
this.aAAToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.bBBToolStripMenuItem});
this.aAAToolStripMenuItem.Name = "aAAToolStripMenuItem";
this.aAAToolStripMenuItem.Size = new System.Drawing.Size(40, 20);
this.aAAToolStripMenuItem.Text = "AAA";
//
// bBBToolStripMenuItem
//
this.bBBToolStripMenuItem.Name = "bBBToolStripMenuItem";
this.bBBToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.bBBToolStripMenuItem.Text = "BBB";
this.bBBToolStripMenuItem.Click += new System.EventHandler(this.bBBToolStripMenuItem_Click);
//
//Form1
//
this.Controls.Add(this.menuStrip1);
}
private void bBBToolStripMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show("BBB");
}
menuStrip中加入菜单
如下:
private System.Windows.Forms.MenuStrip menuStrip1;
private System.Windows.Forms.ToolStripMenuItem aAAToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem bBBToolStripMenuItem;
private void button1_Click(object sender, EventArgs e)
{
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.aAAToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.bBBToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
//
// menuStrip1
//
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.aAAToolStripMenuItem});
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(524, 24);
this.menuStrip1.TabIndex = 3;
this.menuStrip1.Text = "menuStrip1";
//
// aAAToolStripMenuItem
//
this.aAAToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.bBBToolStripMenuItem});
this.aAAToolStripMenuItem.Name = "aAAToolStripMenuItem";
this.aAAToolStripMenuItem.Size = new System.Drawing.Size(40, 20);
this.aAAToolStripMenuItem.Text = "AAA";
//
// bBBToolStripMenuItem
//
this.bBBToolStripMenuItem.Name = "bBBToolStripMenuItem";
this.bBBToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.bBBToolStripMenuItem.Text = "BBB";
this.bBBToolStripMenuItem.Click += new System.EventHandler(this.bBBToolStripMenuItem_Click);
//
//Form1
//
this.Controls.Add(this.menuStrip1);
}
private void bBBToolStripMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show("BBB");
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询