Search code examples
c#formseventstoolstriptoolstripcombobox

ToolStripComboBox events not firing


I have a ToolStripComboBox on a ToolStrip, then my application is minimized to tray and ShowInTaskBar is set to false. After that my application is bring back to normal state. From this moment ToolStripComboBox will not fire any events.

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


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

How can I this events bring back to work?


Solution

  • This is a bug in .NET Framework Windows Forms. After setting ShowInTaskbar = false events will not be raised.

    We can simple make a workaround by calling internal method of Control class just after we set ShowInTaskbar = true;

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

    after that events will be raised properly.

    Another solution: order is important!

    this.Show()
    this.ShowInTaskbar = true;