一个小小的自定义菜单的例子
using System;using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.AutoCAD.Windows;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.EditorInput;
namespace contextMenu
{
public class Class1 : IExtensionApplication
{
ContextMenuExtension m_ContextMenu;
#region IExtensionApplication Members
public void Initialize()
{
throw new NotImplementedException();
AddContextMenu();
}
public void Terminate()
{
throw new NotImplementedException();
RemoveContextMenu();
}
#endregion
void AddContextMenu()
{
try
{
m_ContextMenu = new ContextMenuExtension();
m_ContextMenu.Title = "Acme Employee Menu";
Autodesk.AutoCAD.Windows.MenuItem mi;
mi = new Autodesk.AutoCAD.Windows.MenuItem("Create Employee");
mi.Click += new EventHandler(CallbackOnClick);
m_ContextMenu.MenuItems.Add(mi);
Autodesk.AutoCAD.ApplicationServices.Application.AddDefaultContextMenuExtension(m_ContextMenu);
}
catch
{
}
}
void RemoveContextMenu()
{
try
{
if(m_ContextMenu!=null)
{
Autodesk.AutoCAD.ApplicationServices.Application.RemoveDefaultContextMenuExtension(m_ContextMenu);
m_ContextMenu = null;
}
}
catch{
}
}
void CallbackOnClick(object Sender, EventArgs e)
{
DocumentLock docLock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument();
// AddContextMenu();
docLock.Dispose();
}
}
}
运行没有什么效果,请帮忙看下,不胜感激
throw new NotImplementedException();
全部去掉 谢谢,出来了.为什么要去掉? 初始化事件抛出异常会导致你的dll加载不了 靠,你一加载就抛出异常又不捕获,导致你的程序挂起,当然什么也执行不了 2012好像不能用
页:
[1]