I’ve been working with context menus, and I’m encountering an issue with my code. Currently, I must select object first for the context menu appears. However, I’d like the context menu to appear directly when I right-click the mouse."
This is my example code.
So someone can help me fix this
Thank you !
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Windows;
using System;
public class Commands : IExtensionApplication
{
public void Initialize()
{
CountMenu.Attach();
}
public void Terminate()
{
CountMenu.Detach();
}
}
public class CountMenu
{
private static ContextMenuExtension cme;
public static void Attach()
{
cme = new ContextMenuExtension();
MenuItem mi = new MenuItem("My Custom Menu Item");
mi.Click += new EventHandler(OnMenuItemClick);
cme.MenuItems.Add(mi);
RXClass rxc = Entity.GetClass(typeof(Entity));
Application.AddObjectContextMenuExtension(rxc, cme);
}
public static void Detach()
{
RXClass rxc = Entity.GetClass(typeof(Entity));
Application.RemoveObjectContextMenuExtension(rxc, cme);
}
private static void OnMenuItemClick(object sender, EventArgs e)
{
Application.ShowAlertDialog("Custom menu item clicked!");
}
}
Solved! Go to Solution.
Solved by _gile. Go to Solution.
Hi,
You should use AddDefaultContextMenuExtension instead of AddObjectContextMenuExtension.
your code is working. Suppose i want to make both this:
+ Context Menu Without Object Selection
+ Context Menu With Object Selection
Application.AddDefaultContextMenuExtension(cme);
Application.AddObjectContextMenuExtension(rxc, cme);
I try like this. However It only works for case ''Context Menu Without Object Selection''
Can't find what you're looking for? Ask the community or share your knowledge.