Category / Section
How to add cascading menu items to the context menu in WinForms SyntaxEditor (EditControl)?
1 min read
Cascading menu
The context menu in Essential Edit can be populated with cascading menu items by handling the MenuFill event and adding the menu items to the IContextMenuProvider object associated with the EditControl as shown in code below.
C#
private void editControl1_MenuFill(object sender, System.EventArgs e)
{
ContextMenuManager cmm = sender as ContextMenuManager;
// Add a menu item to the context menu
cmm.AddMenuItem("Bookmarks",new EventHandler(ToggleBookmark));
// Add child menu items to the earlier menu item
IContextMenuProvider contextMenuProvider = this.editControl1.ContextMenuManager.ContextMenuProvider as IContextMenuProvider;
contextMenuProvider.AddContextMenuItem("Bookmarks","Toggle Bookmarks",new EventHandler(ToggleBookmark));
contextMenuProvider.AddContextMenuItem("Bookmarks","Clear Bookmarks",new EventHandler(ClearBookmarks));
// Add a second level of child menu items to the earlier child menu item
contextMenuProvider.AddContextMenuItem("Clear Bookmarks", "ClearAll", new EventHandler(ClearAllBookmarks));
contextMenuProvider.AddContextMenuItem("Clear Bookmarks", "Clear", new EventHandler(ClearBookmark));
}
VB
Private Sub editControl1_MenuFill(sender As Object, e As System.EventArgs) Handles editControl1.MenuFill
Dim cmm As ContextMenuManager = sender
' Add a menu item to the context menu
cmm.AddMenuItem("Bookmarks", New EventHandler(AddressOf ToggleBookmark))
' Add child menu items to the earlier menu item
Dim contextMenuProvider As IContextMenuProvider = Me.editControl1.ContextMenuManager.ContextMenuProvider
contextMenuProvider.AddContextMenuItem("Bookmarks", "Toggle Bookmarks", New EventHandler(AddressOf ToggleBookmark))
contextMenuProvider.AddContextMenuItem("Bookmarks", "Clear Bookmarks", New EventHandler(AddressOf ClearBookmarks))
' Add a second level of child menu items to the earlier child menu item
contextMenuProvider.AddContextMenuItem("Clear Bookmarks", "ClearAll", New EventHandler(AddressOf ClearAllBookmarks))
contextMenuProvider.AddContextMenuItem("Clear Bookmarks", "Clear", New EventHandler(AddressOf ClearBookmark))
End Sub 'editControl1_MenuFill
Reference link: https://help.syncfusion.com/windowsforms/syntax-editor/editing