/// <summary>
/// Show the context menu relative to the provided screen rectangle.
/// </summary>
/// <param name="caller">Reference to object causing the context menu to be shown.</param>
/// <param name="screenRect">Screen rectangle.</param>
/// <param name="horz">Horizontal location relative to screen rectangle.</param>
/// <param name="vert">Vertical location relative to screen rectangle.</param>
/// <param name="keyboardActivated">Was context menu initiated via a keyboard action.</param>
/// <param name="constrain">Should size and position of menu be constrained by display size.</param>
/// <returns>Has the context menu become displayed.</returns>
public bool Show(object caller,
Rectangle screenRect,
KryptonContextMenuPositionH horz,
KryptonContextMenuPositionV vert,
bool keyboardActivated,
bool constrain)
{
bool displayed = false;
// Only need to show if not already displaying it
if (VisualContextMenu == null)
{
// Remember the caller for us in events
Caller = caller;
// Give event handler a change to cancel the open request
CancelEventArgs cea = new CancelEventArgs();
OnOpening(cea);
if (!cea.Cancel)
{
// Set a default reason for the menu being dismissed
CloseReason = ToolStripDropDownCloseReason.AppFocusChange;
// Create the actual control used to show the context menu
VisualContextMenu = CreateContextMenu(this, Palette, PaletteMode,
_redirector, _redirectorImages,
Items, Enabled, keyboardActivated);
// Need to know when the visual control is removed
VisualContextMenu.Disposed += OnContextMenuDisposed;
// Request the menu be shown immediately
VisualContextMenu.Show(screenRect, horz, vert, false, constrain);
// Override the horz, vert setting so that sub menus appear right and below
VisualContextMenu.ShowHorz = KryptonContextMenuPositionH.After;
VisualContextMenu.ShowVert = KryptonContextMenuPositionV.Top;
// Indicate the context menu is fully constructed and displayed
OnOpened(EventArgs.Empty);
// The menu has actually become displayed
displayed = true;
}
}
return(displayed);
}