c# - 如何重新排列上下文菜单条中的项目?

标签 c# .net winforms contextmenustrip

如何重新排列 ContextMenuStrip 的项目?例如,如果我创建一个带有按钮的 Windows 窗体应用程序并将 ContextMenuStrip 添加到窗体并将其分配给按钮单击事件并按顺序添加项目

run process1
run process2
run process3

然后在某天之后,我决定将另一个项目添加到 ContextMenuStrip 说“运行 process4”,我希望序列类似于

run process1
run process4
run process2
run process3

我该怎么做(除了重命名每个项目并交换每个点击事件的代码)?

最佳答案

除了添加项之外,您还可以在指定索引处插入项:

this.contextMenuStrip1.Items.Add("Item1");
this.contextMenuStrip1.Items.Add("Item2");
this.contextMenuStrip1.Items.Add("Item3");
this.contextMenuStrip1.Items.Insert(1, new ToolStripMenuItem("Item4"));

关于c# - 如何重新排列上下文菜单条中的项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48991113/

相关文章:

c# List 不添加项目

c# - Azure 服务总线规则名称最大长度

c# - 使用 MonoDroid 从相机访问全分辨率图片

c# - 如何使用C#将自定义对象保存到Windows Phone8上的sqlite数据库中?

c# - 协方差和 IList

c# - 进行 DPI 缩放的简单方法?

c# - 为什么不相关的属性也在 Winform 数据绑定(bind)中被多次调用,如何解决?

c# - Entity Framework + PostgreSQL 代码优先

.net - 自定义 html 帮助程序 : Create helper with "using" statement support

c# - 如何获取计算机中所有打印机的列表