Hi,
"NodeMouseClick" in Ultra Tree View for getting the Context menu strip.
M.
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); };}
The ContextMenu class exposes a Show method, which takes the control and a location as relative to the control's coordinate system. I don't know of any event that fires when it is about to be displayed.
I have the same problem as malli_436. I want context menu to be shown near the active node when Shift+F10 or "Menu" keyboard key is pressed.
Is there any event like "before context menu open" where I can set the position of the context menu?
I am still unable to position my context menu generated through shortcut at the selected node or the selected cell/row itsel both in Ultra Tree and Ultra win grid.Please help me in finding the solution asap.
Thanks,
M
The Infragistics.Win.UIElement class encapsulates an object's user interface representation. The NodeSelectableAreaUIElement class derives from Infragistics.Win.UIElement; it represents the area of the node which when clicked will cause the node to become selected. This area includes the image and text, but not the expansion indicator.
The UltraTreeNode class exposes a UIElement property, which returns an object of type TreeNodeUIElement. This element represents the node's physical representation in the user interface. The UIElement class exposes a Rect property, which returns the bounds for the element, expressed in client coordinates. Note that the UltraTreeNode's UIElement property can under normal circumstances return null, which it does when the node is not in the viewable area of the control. When it returns a non-null value, you can convert the Location component of the Rect property to screen coordinates to determine the screen location of the node.