Replies
After investigating Infragistic's code using Reflector I see that
when context menu is opened via keyboard, it is shown at the center of
the parent control and there is no way to override this behavior. So I've tried to do something similar to what
UltraToolbarsManager.SetContextmenuUltra does but simplified. It works similar to Windows Explorer.
I've
created a class inherited from UltaTree and added the following code:
private bool contextMenuShortcutPressed_;
public MyTree()
{
KeyDown += (sender, e) =>
{
if (e.KeyCode == Keys.Apps || (e.KeyCode == Keys.F10 && e.Modifiers == Keys.Shift))
{
contextMenuShortcutPressed_ = true;
}
};
}
public void SetContextMenu(PopupMenuTool popupMenuTool)
{
if (ContextMenu != null)
{
ContextMenu.Dispose();
}
ContextMenu = new ContextMenu();
ContextMenu.Popup += (sender, e) =>
{
Point screenPoint;
if (contextMenuShortcutPressed_)
{
Point controlPoint;
var activeNode = ActiveNode;
if (activeNode != null)
{
var labelElement = activeNode.UIElement.GetDescendant(typeof(EditorWithTextUIElement));
var activeNodeRect = labelElement == null ? activeNode.UIElement.Rect : labelElement.Rect;
controlPoint = new Point(activeNodeRect.X, activeNodeRect.Y + activeNodeRect.Height / 2);
}
else
{
var rect = UIElement.Rect;
controlPoint = new Point((rect.Left + rect.Right) / 2, (rect.Top + rect.Bottom) / 2);
}
screenPoint = PointToScreen(controlPoint);
}
else
{
screenPoint = MousePosition;
}
contextMenuShortcutPressed_ = false;
popupMenuTool.ShowPopup(screenPoint, Rectangle.Empty, DropDownPosition.BelowExclusionRect);
};
}