0

我在 ToolStrip 上有一个 ToolStripComboBox,然后我的应用程序被最小化到托盘并且 ShowInTaskBar 设置为 false。之后,我的应用程序恢复正常状态。从此刻开始 ToolStripComboBox 不会触发任何事件。

this.ShowInTaskbar = false;
this.WindowState = FormWindowState.Minimized;


this.ShowInTaskbar = true;
this.WindowState = FormWindowState.Normal;
this.Show();

我怎样才能让这些事件恢复工作?

4

1 回答 1

0

这是 .NET Framework Windows 窗体中的一个错误。设置后ShowInTaskbar = false不会引发事件。

我们可以通过在设置后调用 Control 类的内部方法来简单地解决问题ShowInTaskbar = true

MethodInfo dynMethod = toolStripComboBox1.ComboBox.GetType().GetMethod("RecreateHandleCore",BindingFlags.NonPublic | BindingFlags.Instance); 
dynMethod.Invoke(toolStripComboBox1.ComboBox, new object[] {});

之后,事件将正确引发。

另一个解决方案:顺序很重要!

this.Show()
this.ShowInTaskbar = true;
于 2014-06-18T05:08:39.257 回答