Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
710
How to detect click on an image vs click on the node's text.
posted

In a treeview, I need to be able to determine what part of a node has been clicked by the mouse.  Mostly I need to differentiate between a click on a left image and a click on the node's text.

Parents
  • 69832
    Suggested Answer
    Offline posted

    You could use the UIElement.ElementFromPoint method to hit test for an ImageUIElement:

    private void ultraTree1_MouseDown(object sender, MouseEventArgs e)
    {
        UltraTree tree = sender as UltraTree;
        UIElement controlElement = tree.UIElement;
        UIElement elementAtPoint = controlElement != null ? controlElement.ElementFromPoint( e.Location ) : null;
        bool imageAtPoint = false;
        while ( elementAtPoint != null )
        {
            if ( elementAtPoint is ImageUIElement )
            {
                imageAtPoint = true;
                break;
            }

            elementAtPoint = elementAtPoint.Parent;
        }

        if ( imageAtPoint )
        {
        }
    }

Reply Children