gpt4 book ai didi

c# - 如何在 Windows 应用程序中按名称动态创建 ToolStripMenuItem?

转载 作者:可可西里 更新时间:2023-11-01 11:23:27 33 4
gpt4 key购买 nike

表格 2:

private ToolStripMenuItem mHelp;
private ToolStripMenuItem apProposToolStripMenuItem;
public void intializecomponent()
{
this.mHelp = new ToolStripMenuItem();
this.contentsToolStripMenuItem = new ToolStripMenuItem();
this.apProposToolStripMenuItem = new ToolStripMenuItem();
this.mHelp.DropDownItems.AddRange(new ToolStripItem[2]
{
(ToolStripItem) this.contentsToolStripMenuItem,
(ToolStripItem) this.apProposToolStripMenuItem
});
this.mHelp.Name = "mHelp";
this.mHelp.Size = new Size(44, 20);
this.mHelp.Text = "Help";
this.contentsToolStripMenuItem.Name = "contentsToolStripMenuItem";
this.contentsToolStripMenuItem.Size = new Size(122, 22);
this.contentsToolStripMenuItem.Text = "Contents";
this.contentsToolStripMenuItem.Click += new EventHandler(this.contentsToolStripMenuItem_Click);
this.apProposToolStripMenuItem.Image = (Image) componentResourceManager.GetObject("apProposToolStripMenuItem.Image");
this.apProposToolStripMenuItem.Name = "apProposToolStripMenuItem";
this.apProposToolStripMenuItem.Size = new Size(122, 22);
this.apProposToolStripMenuItem.Text = "About";
this.apProposToolStripMenuItem.Click += new EventHandler(this.apProposToolStripMenuItem_Click);
this.Load += new EventHandler(this.DocumentSpace_Load);
}

如何在窗体上找到apProposToolStripMenuItem?我试图删除特定的 ToolStripMenuItem,但它不起作用,而且我找不到 apProposToolStripMenuItem

表格 1:

ToolStripMenuItem mi = new ToolStripMenuItem("apProposToolStripMenuItem") { Name = "About" };
mi.DropDownItems.RemoveByKey("About");

最佳答案

您可以像这样通过名称删除它:

mHelp.DropDownItems.RemoveByKey("apProposToolStripMenuItem");

你也可以像这样直接删除它:

var about = mHelp.DropDownItems["apProposToolStripMenuItem"]
mHelp.DropDownItems.Remove(about);

关于c# - 如何在 Windows 应用程序中按名称动态创建 ToolStripMenuItem?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53894061/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com