private void OnClick(object sender, MouseEventArgs e)
{
// Never show a context menu in design mode
if (!CommonHelper.DesignMode(_manager.Control))
{
// Fire the event handlers hooked into the button spec click event
_buttonSpec.PerformClick(e);
// Does the button spec define a krypton context menu?
if ((_buttonSpec.KryptonContextMenu != null) && (ViewButton != null))
{
// Convert from control coordinates to screen coordinates
Rectangle rect = ViewButton.ClientRectangle;
Point pt;
// If the button spec is on the chrome titlebar then find position manually
if (_manager.Control is Form)
{
pt = new Point(_manager.Control.Left + rect.Left, _manager.Control.Top + rect.Bottom + 3);
}
else
{
pt = _manager.Control.PointToScreen(new Point(rect.Left, rect.Bottom + 3));
}
// Show the context menu just below the view itself
_buttonSpec.KryptonContextMenu.Closed += new ToolStripDropDownClosedEventHandler(OnKryptonContextMenuClosed);
if (!_buttonSpec.KryptonContextMenu.Show(_buttonSpec, pt))
{
// Menu not being shown, so clean up
_buttonSpec.KryptonContextMenu.Closed -= new ToolStripDropDownClosedEventHandler(OnKryptonContextMenuClosed);
// Not showing a context menu, so remove the fixed view immediately
_finishDelegate?.Invoke(this, EventArgs.Empty);
}
}
else if ((_buttonSpec.ContextMenuStrip != null) && (ViewButton != null))
{
// Set the correct renderer for the menu strip
_buttonSpec.ContextMenuStrip.Renderer = _manager.RenderToolStrip();
// Convert from control coordinates to screen coordinates
Rectangle rect = ViewButton.ClientRectangle;
Point pt = _manager.Control.PointToScreen(new Point(rect.Left, rect.Bottom + 3));
// Show the context menu just below the view itself
VisualPopupManager.Singleton.ShowContextMenuStrip(_buttonSpec.ContextMenuStrip, pt, _finishDelegate);
}
else
{
// Not showing a context menu, so remove the fixed view immediately
_finishDelegate?.Invoke(this, EventArgs.Empty);
}
}
else
{
// Not showing a context menu, so remove the fixed view immediately
_finishDelegate?.Invoke(this, EventArgs.Empty);
}
}