Files
docs-desktop/dotnet-desktop-guide/framework/winforms/controls/how-to-attach-a-shortcut-menu-to-a-treenode-using-the-designer.md
T
Andy De George c0ba284473 Initial winforms content migrated (#18)
* Merge winforms framework content to working branch (#14)

* Breadcrumb / TOC / Move net5 to net folder (#15)

* change path from net5 to net

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Mess with bread/toc

* Add .net 5 winforms placeholder article (#16)

* added some metadata and adjusted net5 placeholder

* corrections

* corrections

* corrections

* Test1

* Swapping landing page vs concept

* fix links

* Fix links

* Fix desc
2020-09-01 16:26:21 -07:00

2.4 KiB

title, ms.date, helpviewer_keywords, ms.assetid
title ms.date helpviewer_keywords ms.assetid
How to: Attach a Shortcut Menu to a TreeNode Using the Designer 03/30/2017
shortcut menus [Windows Forms], attaching to TreeNodes
TreeNode [Windows Forms], attaching a shortcut menu using Designer
8e45e184-1313-4f8f-90ff-2cd5789b2268

How to: Attach a Shortcut Menu to a TreeNode Using the Designer

The Windows Forms xref:System.Windows.Forms.TreeView control displays a hierarchy of nodes, similar to the files and folders displayed in the left pane of the Windows Explorer feature in Windows operating systems. By setting the xref:System.Windows.Forms.Control.ContextMenuStrip%2A property, you can provide context-sensitive operations to the user when they right-click the xref:System.Windows.Forms.TreeView control. By associating a xref:System.Windows.Forms.ContextMenuStrip component with individual xref:System.Windows.Forms.TreeNode items, you can add a customized level of shortcut menu functionality to your xref:System.Windows.Forms.TreeView controls.

To associate a shortcut menu with a TreeNode at design time

  1. Add a xref:System.Windows.Forms.TreeView control to your form, and then add nodes to the xref:System.Windows.Forms.TreeView as needed. For more information, see How to: Add and Remove Nodes with the Windows Forms TreeView Control.

  2. Add a xref:System.Windows.Forms.ContextMenuStrip component to your form, and then add menu items to the shortcut menu that represent node-level operations you wish to make available at run time. For more information, see How to: Add Menu Items to a ContextMenuStrip.

  3. Reopen the TreeNodeEditor dialog box for the xref:System.Windows.Forms.TreeView control, select the node to edit, and set its xref:System.Windows.Forms.ContextMenuStrip property to the shortcut menu that you added.

  4. When this property is set, the shortcut menu will be displayed when you right-click the node.

    Additionally, you will want to write code to handle the xref:System.Windows.Forms.ToolStripItem.Click events for these menu items.

See also