我有一个包含可供选择的子菜单的ToolStripMenuItem。问题是,它们在错误的地方显示:

我有用于上述项的子菜单(这是用于解决方案的ToolStripCombobox -Thank you Reza )的代码,但是我很难调整以使它在ToolStripMenuItem中工作,因为它不包含Control.Parent.GetType():
private void Form_Load(object sender, EventArgs e)
{
var item = toolStripComboBox;
var createControl = item.Control.Parent.GetType().GetMethod("CreateControl",
System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
createControl.Invoke(item.Control.Parent, new object[] { true });一如既往,任何帮助都是值得感激的。
发布于 2016-11-17 01:29:19
我认为整个问题的根源在于使用表单加载事件处理程序而不是表单构造函数。当我运行以下代码时,当表单加载时,菜单项位于正确的位置:
public Form1()
{
InitializeComponent();
ToolStripComboBox item1 = new ToolStripComboBox();
item1.Items.AddRange(new object[]
{
"One",
"Two",
"Thtree"
});
item1.DropDownStyle = ComboBoxStyle.Simple;
menuStrip1.Items.Add(item1);
ToolStripMenuItem item2 = new ToolStripMenuItem();
item2.Text = "Four";
menuStrip1.Items.Add(item2);
}https://stackoverflow.com/questions/40644839
复制相似问题