[求助]《深居浅出AutoCAD二次开发(李冠亿)》中的添加Ribbon菜单例程编译错误
我用的是AutoCad2009,编译该书中的示例代码时出现以下错误1 “Autodesk.Windows.RibbonItemEnumerator”不包含“Add”的定义,并且找不到可接受类型为“Autodesk.Windows.RibbonItemEnumerator”的第一个参数的扩展方法“Add”(是否缺少 using 指令或程序集引用?) E:\AutoCAD\Arx\参考\SJQCSample\用户交互\用户界面\菜单\Ribbon.cs 25 29 Sample
......
AcDbMgd, AcMgd, AdWindows, PresentationCore, PresentationFramework , WindowsBase这些引用我都添加了
请高手帮忙。
/////////////////////////////////////////////////////////////////////////////////////////////////
//http://www.bimcad.org 数字建筑
//深居浅出AutoCAD二次开发(李冠亿)
/////////////////////////////////////////////////////////////////////////////////////////////////
using System;
using Autodesk.Windows;
using Autodesk.AutoCAD.Runtime;
namespace Sample
{
class Ribbon
{
public void AddRibbon()
{
RibbonControl rc = RibbonControl();
RibbonTab rt = RibbonTab("菜单标签", "1");
RibbonPanel rp = RibbonPanel("菜单面板");
RibbonButton rb = RibbonButton("菜单按钮", "菜单命令");
rp.Source.Items.Add(rb);
rt.Panels.Add(rp);
rc.Tabs.Add(rt);
}
/// <summary>
/// 获得菜单控制
/// </summary>
/// <returns></returns>
public static RibbonControl RibbonControl()
{
if (Autodesk.Windows.ComponentManager.Ribbon == null)
Autodesk.Windows.ComponentManager.ItemInitialized += new EventHandler<RibbonItemEventArgs>(ComponentManager_ItemInitialized);
return ComponentManager.Ribbon; //Autodesk.AutoCAD.Ribbon.RibbonServices.RibbonPaletteSet.RibbonControl; //
}
/// <summary>
/// 创建菜单标签
/// </summary>
/// <param name="Name">标签名</param>
/// <param name="id">标签ID</param>
/// <returns></returns>
public static RibbonTab RibbonTab(string Name, string id)
{
RibbonTab ribTab = new Autodesk.Windows.RibbonTab();
ribTab.Title = Name;
ribTab.Id = id;
ribTab.IsActive = true;
return ribTab;
}
/// <summary>
/// 创建菜单面板
/// </summary>
/// <param name="Title">面板名</param>
/// <returns></returns>
public static RibbonPanel RibbonPanel(string Title)
{
RibbonPanelSource ribSourcePanel = new RibbonPanelSource(); // Autodesk.Windows
ribSourcePanel.Title = Title;//now the panel
RibbonPanel ribPanel = new RibbonPanel();
ribPanel.Source = ribSourcePanel;
return ribPanel;
}
/// <summary>
/// 创建菜单按钮
/// </summary>
/// <param name="btName">按钮名</param>
/// <param name="cmdName">命令名</param>
/// <returns></returns>
public static RibbonButton RibbonButton(string btName, string cmdName)
{
RibbonButton ribButton = new RibbonButton();
ribButton.Text = btName;
ribButton.CommandParameter = cmdName;
ribButton.ShowText = true;
ribButton.CommandHandler = new AdskCommandHandler();
return ribButton;
}
/// <summary>
/// 用于激活菜单
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
static void ComponentManager_ItemInitialized(object sender, RibbonItemEventArgs e)
{
if (Autodesk.Windows.ComponentManager.Ribbon != null)
Autodesk.Windows.ComponentManager.ItemInitialized -= new EventHandler<RibbonItemEventArgs>(ComponentManager_ItemInitialized);
}
/// <summary>
/// 执行按钮的命令
/// </summary>
public class AdskCommandHandler : System.Windows.Input.ICommand
{
/// <summary>
/// 是否可执行(接口)
/// </summary>
/// <param name="parameter">命令名</param>
/// <returns></returns>
public bool CanExecute(object parameter)
{
return true;
}
/// <summary>
/// 改变可执行状态
/// </summary>
public event EventHandler CanExecuteChanged;
/// <summary>
/// 执行命令
/// </summary>
/// <param name="parameter">命令的名字</param>
public void Execute(object parameter)
{
//is from a Ribbon Button?
RibbonButton ribBtn = parameter as RibbonButton;
if (ribBtn != null)
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.SendStringToExecute((String)ribBtn.CommandParameter, true, false, true);
//is from s Ribbon Textbox?
RibbonTextBox ribTxt = parameter as RibbonTextBox;
if (ribTxt != null)
System.Windows.Forms.MessageBox.Show(ribTxt.TextValue);
}
}
}
}
哪个手册的? 回复 雪山飞狐_lzh 的帖子
刚才标题搞错了,应该是《深居浅出AutoCAD二次开发(李冠亿)》这个书中的。 Ribbon在官网教程应该可以找到一些例子吧 回复 雪山飞狐_lzh 的帖子
可以给一个Ribbon官网教程的下载地址吗? http://www.adskconsulting.com/adn/cs/api_course_sched.php 正想用编一个ribbon工具栏 呃,说老实话吧,感觉这本书写的真不咋地,不过有总比没有强~~ 我的也是出现了异常:
警告 1 从不使用事件“Sample.Ribbon.AdskCommandHandler.CanExecuteChanged” d:\my documents\visual studio 2010\Projects\sample5\sample5\Class1.cs 102 39 sample5
09的有这个方法吗?不知道他的类库是不是完整的
页:
[1]
2