明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 3425|回复: 3

[求助]怎么不能添加菜单?

[复制链接]
发表于 2009-5-7 12:05:00 | 显示全部楼层 |阅读模式

下面是我根据autodesk系列产品开发教程 写的一段代码,我想往AutoCAD2008中加菜单,但怎么加不上?

请高手帮我看看!

using System;
using System.Collections.Generic;
using System.Text;
using Autodesk.AutoCAD.ApplicationServices;

using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Windows;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using System.Windows.Forms;
namespace cl
{
    class Class2Menu
    {
        [CommandMethod("Addmenu")]
        public void Addmenu()
        {
            AddContextMenu();

        }
        public ContextMenuExtension m_ContextMenu;
        private void AddContextMenu()
        {    
            m_ContextMenu = new ContextMenuExtension();
            m_ContextMenu.Title = "工程图系统";
            Autodesk.AutoCAD.Windows.MenuItem mi;
            mi = new Autodesk.AutoCAD.Windows.MenuItem("用户管理");
            mi.Click += MenuUserM_OnClick;
            m_ContextMenu.MenuItems.Add(mi);
            Autodesk.AutoCAD.ApplicationServices.Application.AddDefaultContextMenuExtension(m_ContextMenu);   
          
        }

        private void MenuUserM_OnClick(object Sender, EventArgs e)
        {
          
            MessageBox.Show("用户管理");       
          
        }
    }
}

发表于 2009-5-7 13:34:00 | 显示全部楼层
public static void AddSModelPopupMenu()
    {
      try
      {
        AcadMenuGroups mnus = (AcadMenuGroups)app.MenuGroups;
        AcadPopupMenus pmnus = mnus.Item(1).Menus;
        int count = 0;
        foreach (AcadPopupMenu mnu in pmnus)
        { 
          if (mnu.OnMenuBar == true) count++;
        }
        AcadPopupMenu Menu_SModel = pmnus.Add("&Module");
        string macro = Convert.ToChar(Keys.Escape).ToString();     
        AcadPopupMenuItem MenuItem_MainForm = Menu_SModel.AddMenuItem(Menu_SModel.Count, "&MainForm", macro + "SMF ");
        MenuItem_MainForm.HelpString = "Show main window";
        AcadPopupMenuItem MenuItem_SetBoard = Menu_SModel.AddMenuItem(Menu_SModel.Count, "Set &Board", macro + "mBoardW ");
        MenuItem_SetBoard.HelpString = "Set Board Width";
      
        if (count == 0)//下拉菜单不同时间的装载情况会不一样
          pmnus.InsertMenuInMenuBar("&Module", count + 12);//AutoCAD 2006 有13个下拉菜单项
        else
          pmnus.InsertMenuInMenuBar("&Module", ++count);
      }
      catch (System.Exception ex)
      {      
      }
    }
 楼主| 发表于 2009-5-7 15:44:00 | 显示全部楼层
宏的用法一点不会啊,我是刚学autocad二次开发!感觉真难
 楼主| 发表于 2009-5-8 20:05:00 | 显示全部楼层
sieben发表于2009-5-7 13:34:00public static void AddSModelPopupMenu()    {      try      {        AcadMenuGro

非常感谢,问题已经解决,感谢群友的热心帮助!

这是一个和谐的社会!

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-29 07:28 , Processed in 0.176474 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表