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

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)