ToolStripCombobox displays at the top left corner

2019-03-06 10:48发布

I have a ToolStripCombobox that when I set its DropDownStyle to Simple. The first time which I open the menu, it displays at the top left corner of the screen. However, when I select the same item for the second time, it displays in the correct location.

Is there a way to prevent the code from showing the list at the top left corner of the screen?

Thank you in advance for any help.

First Time

Result 1

Second Time

Result 2

1条回答
成全新的幸福
2楼-- · 2019-03-06 11:45

To solve the problem put this code in the Load event of form:

var item = toolStripComboBox1;
var createControl = item.Control.Parent.GetType().GetMethod("CreateControl",
    System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
createControl.Invoke(item.Control.Parent, new object[] { true });

It's a strange bug and I don't have any idea why the ToolStripComboBox with DisplayStyle set to Simple suffers from this bug but by setting DisplayStyle to DropDown or DropDownList doesn't have this bug.

Using above code, I forced the owner ToolStripDropDownMenu be created before being shown.

查看更多
登录 后发表回答