日期:2014-05-18  浏览次数:21150 次

用C#开发AutoCAD新手求救
我想实现如下功能:在AutoCAD上创建自己的菜单,菜单标签下有自己的按钮。我从网上抄了一段代码,创建了一个WPF自定义控件,代码如下:
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.Windows;


namespace WpfCustomControlLibrary3
{
   
  public class CustomControl1 : Control
  {
  [CommandMethod("test")]
  void test()
  {
  //创建一个按钮
  RibbonButton button = new RibbonButton();
  button.Text = "ClickMe";
  button.Orientation = Orientation.Vertical;
  button.Size = RibbonItemSize.Large;
  button.Id = "ClickMe_1";

  //创建RibbonRow用来放置按钮
  RibbonRow row = new RibbonRow();
  row.Items.Add(button);

  //创建RibbonPanelSource,用来放置RibbonRow
  RibbonPanelSource panelSource = new RibbonPanelSource();
  panelSource.Title = "Custom Panel";
  panelSource.Rows.Add(row);

  //再创建一个RibbonPanel来放置上面的RibbonSource
  RibbonPanel panel = new RibbonPanel();
  panel.Source = panelSource;

  //创建AutoCAD菜单标签,放置RibbonPanel
  RibbonTab tab = new RibbonTab();
  tab.Title = "Custom Tab";
  tab.IsContextualTab = false;
  tab.Panels.Add(panel);

  //RibbonControl是所有AutoCAD控制按钮的基础
  RibbonControl ribbonControl = Autodesk.AutoCAD.Ribbon.RibbonServices.RibbonPaletteSet.RibbonControl;
  ribbonControl.Tabs.Add(tab);

  //激活标签,响应事件
  ribbonControl.ActiveTab = tab;
  button.Click += new RoutedEventHandler(button_Click);
  }

  private static void button_Click(Object sender, RoutedEventArgs e)
  {
  RibbonButton button = sender as RibbonButton;
  if (button != null && (button.Id == "ClickMe_1"))
  {
  MessageBox.Show("click");
  e.Handled = true;
  }
  }
  static CustomControl1()
  {
  DefaultStyleKeyProperty.OverrideMetadata(typeof(CustomControl1), new FrameworkPropertyMetadata(typeof(CustomControl1)));
  }
  }
}
调试用的是AutoCAD2010版,但是输入test命令提示未知命令,请哪位高手指教

------解决方案--------------------
y用現成的控件

網站

my blog
http://ufo-crackerx.blog.163.com/
------解决方案--------------------
这个怎么解决的兄弟,我的也是一样不管用,在2008里没遇到过此问题啊,怎么到2010就出现这问题?