ToolStripMenuItem 项目显示在错误的位置

ToolStripMenuItem items show in the incorrect location

我有一个 ToolStripMenuItem,其中包含来自 select 的子菜单。问题是它们显示在错误的位置:

我有用于上述项目的子菜单的代码(这是用于 ToolStripCombobox -谢谢 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 });

一如既往,我们将不胜感激。

我认为您整个问题的根源在于您使用表单加载事件处理程序而不是表单构造函数。当我 运行 以下代码时,菜单项在表单加载时位于正确的位置:

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);
}