Util.Menus
Download: Util.Menus.zip
Util.Menus adds an object Tag property to menus and menu items, and provides a standard edit context menu.
Tagged Menus
All WinForms controls have a standard object Tag property, which allows you to associate arbitrary data with a form control. While they have visual representations, menus and menu items are derived from Component instead of Control and lack the Tag property.
The TaggedMenu and TaggedMenuItem classes add a Tag property. This is especially useful for menus created at runtime, as data for the event handler can be put into the tag.
Edit Context Menu
Starting with Windows 95, right-clicking on a text field with no custom context menu will show the system default edit menu. This is the menu with "Cut", "Copy", "Paste", etc. Once you add a context menu to a text control, this edit menu disappears. There is no way to a copy of this menu from the system, so applications must implement it themselves if they want to keep that functionality.
The EditContextMenu class implements a standard edit menu in C#. Call EditContextMenu.AddTo(ContextMenu menu) to add Undo/Cut/Copy/Paste/Clear/SelectAll to a context menu.
There is a known problem with .NET 1.x, where RichTextBox does not set the SourceControl property for its context menu. To use this edit menu with a rich text control, change your ContextMenu to a TaggedMenu in your form, and then set the menu's Tag to the rich text control.
Examples
The included demo project shows how to use EditContextMenu with normal and rich text boxes. The source to EditContextMenu shows how to use TaggedMenuItem.
Contact Information
- Email:

