private void PerformClick()
{
SWF.ToolStripItem item = (SWF.ToolStripItem)Provider.Component;
if (item.Owner != null && item.Owner.InvokeRequired)
{
item.Owner.BeginInvoke(new SWF.MethodInvoker(PerformClick));
return;
}
var currentParent = item.OwnerItem as SWF.ToolStripMenuItem;
// Invoking without a visible parent results in exceptions
if (currentParent != null && !currentParent.DropDown.Visible)
{
return;
}
var dropdown = item as SWF.ToolStripDropDownItem;
bool hide = false;
if (dropdown != null)
{
hide = dropdown.Pressed;
}
// Make sure selection changes, or else another item's
// dropdown menu might still appear.
if (item.Owner != null)
{
item.Select();
}
item.PerformClick();
// PerformClick does _not_ show/hide the DropDown, so
// we must do this manually. On Vista, clicking the
// button appears to both Show the drop down and
// Perform a click, so we emulate that behavior.
if (dropdown != null && !(item is SWF.ToolStripSplitButton))
{
if (hide)
{
dropdown.HideDropDown();
}
else
{
dropdown.ShowDropDown();
}
}
}