Home Forums WinForms controls Other WinForms controls Different ContextMenu on Icon or on Text in a TreeView

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #18038 |

    I want to add Context Menu functionality to the TreeView.
    But I need a different context Menu when clicked on a node text or a node icon.

    Does anyone now how to test whether the user clicked on the icon or on the text?

    Imported from legacy forums. Posted by Jan (had 2154 views)

    User (Old forums)
    Member
    Post count: 23064

    Tech support solved the the ‘problem’ 🙂 .

    Here is the code snippet.

    private void node_MouseDown(object sender, MouseEventArgs e)
    {
    if( e.Button == MouseButtons.Right )
    {
    SmartItem item = (SmartItem)sender;
    Rectangle iconRect = new Rectangle( item.DisplayRectangle.X, item.DisplayRectangle.Y, 20, 20 );

    if( iconRect.Contains( e.X, e.Y ) )
    {
    System.Diagnostics.Debug.WriteLine( “right-click on icon” );
    }
    else
    {
    System.Diagnostics.Debug.WriteLine( “right-click on text” );
    }
    }
    }

    Imported from legacy forums. Posted by Jan (had 3045 views)

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.