Add/Remove the ContextMenu item from WinForms EditControl embedded ContextMenu.
WinForms EditControl has default embedded ContextMenu. This ContextMenu supports to add/remove the ContextMenuItem. It can be achieved using below functions.
AddContextMenuItem: Used to add the ContextMenuItem.
RemoveContextMenuItem: Used to remove the ContextMenuItem from the Embedded ContextMenu by passing the below corresponding ContextMenuItem Text. Please make use of the below ContextMenuItem Text.
ContextMenuItem | Corresponding Item Text |
1.Edit
Cut Copy Paste Delete Undo Redo Find… Replace… Go to… Select All Delete All
2. File
New Open… Close Save Save As… Print Preview
3. Advanced
Tabify Selection Untabify Selection Indent Selection Unindent Selection Comment Selection Uncomment Expand All Collapse All
4. Bookmarks
Toggle Bookmark Next Bookmark Previous Bookmark Clear Bookmarks
5. Options…
|
1. &Edit
“Cu&t” “Cop&y” “&Delete” “&Paste” “&Undo” “R&edo” “&Find” “&Replace” “&Go to…” “&Select All” “De&lete All”
2. “&File”
“&New” “&Open…” “&Close” “&Save” “Save &As..” “Print Pre&view” “&Print”
3. “&Advanced”
“&Tabify Selection” “&Untabify Selection” “&Indent Selection” “&U&nindent Selection” “&Comment Selection” “Unc&omment Selection” “&Exapnd All” “Co&llapse All”
4. “&Bookmarks”
“Toggle Bookmark” “Next Bookmark” “Previous Bookmark” “Clear Bookmarks”
5. “&Options…” |
The following code demonstrates the same.
C#
// Handle the FillMenu event which is called each time the context menu is displayed. this.editControl1.ContextMenuManager.FillMenu += ContextMenuManager_FillMenu; //Add ContextMenuItem this.editControl1.ContextMenuManager.ContextMenuProvider.AddContextMenuItem("&Find", show1); this.editControl1.ContextMenuManager.ContextMenuProvider.AddContextMenuItem("&Replace", ShowReplaceDialog); this.editControl1.ContextMenuManager.ContextMenuProvider.AddContextMenuItem("&Goto", ShowGoToDialog); //Remove ContextMenu Item this.editControl1.ContextMenuManager.ContextMenuProvider.RemoveContextMenuItem("&Edit"); this.editControl1.ContextMenuManager.ContextMenuProvider.RemoveContextMenuItem("&Options…"); this.editControl1.ContextMenuManager.ContextMenuProvider.RemoveContextMenuItem("&Save"); this.editControl1.ContextMenuManager.ContextMenuProvider.RemoveContextMenuItem("Save &As...");
VB
'Raise the event that used to set Add/Remove the ContextmenuItem AddHandler Me.editControl1.ContextMenuManager.FillMenu, AddressOf ContextMenuManager_FillMenu ''Add ContextMenuItem Me.editControl1.ContextMenuManager.ContextMenuProvider.AddContextMenuItem("&Find", AddressOf show1) Me.editControl1.ContextMenuManager.ContextMenuProvider.AddContextMenuItem("&Replace", AddressOf ShowReplaceDialog) Me.editControl1.ContextMenuManager.ContextMenuProvider.AddContextMenuItem("&Goto", AddressOf ShowGoToDialog) 'Remove ContextMenu Item Me.editControl1.ContextMenuManager.ContextMenuProvider.RemoveContextMenuItem("&New") Me.editControl1.ContextMenuManager.ContextMenuProvider.RemoveContextMenuItem("&Options...") Me.editControl1.ContextMenuManager.ContextMenuProvider.RemoveContextMenuItem(“Cop&y”) Me.editControl1.ContextMenuManager.ContextMenuProvider.RemoveContextMenuItem("Save &As...")
Screenshot
Figure 1: Default ContextMenu.
Figure 2: After Remove Save As... from File ContextMenu Item.
Samples:
Conclusion
I hope you enjoyed learning about how to Add/Remove the ContextMenuItem from EditControl Embedded ContextMenu.
You can refer to our WinForms EditControl feature tour page to know about its other groundbreaking feature representations. You can also explore our WinForms EditContro documentation to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!