1

我想在运行时将子菜单添加到主菜单中。我查看了其他帖子 在运行时添加到条形菜单, 但我不明白我在这里缺少什么,因为它只填充一个项目,但我在文件夹中有三个 xml 文件。下面是代码。testsuite 参数包含 xml 文件。

    public void LoadTestSuiteMenuStrip(string[] testsuite)
    {
        try
        {
            foreach (var temp in testsuite)
            {
                int max = temp.Length-1;
                while (temp[max] != '\\')
                    max--;

                max++;

                //remove the folder path and take only xml file name
                string name = temp.Substring(max, temp.Length - max);

                ToolStripMenuItem subItem = new ToolStripMenuItem(name);
                //subItem.DisplayStyle = ToolStripItemDisplayStyle.Text;
                //subItem .Text = name;
                //subItem .Name = name;
                //subItem.Tag = name;
                subItem.Click += new EventHandler(testSuiteToolstrip_Click);
                testsuiteToolStripMenuItem.DropDownItems.Add(subItem);
            }
        }
        catch (Exception error)
        {
        }
    }

谢谢

4

1 回答 1

0

确保从主线程访问 GUI。如果要从其他线程添加项目,而不是

LoadTestSuiteMenuStrip(args);

利用

Invoke(new Action<string[]>(LoadTestSuiteMenuStrip), new object[] { args });
于 2012-07-27T02:26:53.117 回答