Use “AddObjectContextMenuExtension” API passing the type of the class and the content menu to attach a menu to an entity type. Refer below code sample.
[CommandMethod("ContextMenuExtTest")]
static public void ContextMenuExtTest()
{
ContextMenuExtension contectMenu =
new ContextMenuExtension();
MenuItem item0 = new MenuItem("Line context menu");
contectMenu.MenuItems.Add(item0);
MenuItem Item1 = new MenuItem("Test1");
Item1.Click += new EventHandler(Test1_Click);
item0.MenuItems.Add(Item1);
MenuItem Item2 = new MenuItem("Test2");
Item2.Click += new EventHandler(Test2_Click);
item0.MenuItems.Add(Item2);
//for custom entity, replace the "Line" with .NET
//(managed) wrapper of custom entity
Application.AddObjectContextMenuExtension(
Line.GetClass(typeof(Line)), contectMenu);
}
static void Test1_Click(object sender, EventArgs e)
{
Application.ShowAlertDialog("Test1 clickedn");
}
static void Test2_Click(object sender, EventArgs e)
{
Application.ShowAlertDialog("Test2 clickedn");
}

Leave a Reply