- 积分
- 344
- 明经币
- 个
- 注册时间
- 2010-10-21
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.Windows;
using Autodesk.AutoCAD.Runtime;
using System.Windows.Forms;
namespace menu
{
public class Class1
{
[CommandMethod("SendCommand")]
public void SendCommand()
{
MessageBox.Show("dddd");
}
[CommandMethod("AddRibbon")]
public void AddRibbon()
{
Autodesk.AutoCAD.ApplicationServices.Application.MainWindow.Text = "CGBridge";
RibbonControl rc = RibbonControl();
RibbonTab rt = RibbonTab("系统", "1");
RibbonPanel rp = RibbonPanel("菜单面板");
RibbonButton rblogin = RibbonButton("登陆系统", "登陆系统", "\\Demo.bmp");
RibbonButton rbconnect = RibbonButton("连接设置", "连接设置", "\\Demo.bmp");
RibbonButton rbdatain = RibbonButton("数据加载", "数据加载", "\\Demo.bmp");
RibbonButton rbuser = RibbonButton("用户管理", "用户管理", "\\Demo.bmp");
RibbonButton rbquit = RibbonButton("系统退出", "系统退出", "\\Demo.bmp");
rp.Source.Items.Add(rblogin);
rp.Source.Items.Add(rbconnect);
rp.Source.Items.Add(rbdatain);
rp.Source.Items.Add(rbuser);
rp.Source.Items.Add(rbquit);
rt.Panels.Add(rp);
RibbonTab rtedit = RibbonTab("要素编辑", "1");
RibbonPanel rpedit = RibbonPanel("菜单");
RibbonButton rbaddpoint = RibbonButton("增加点", "增加点", "\\Demo.bmp");
RibbonButton rbaddpolyline = RibbonButton("增加折线", "增加折线", "\\Demo.bmp");
RibbonButton rbaddpolygon = RibbonButton("增加区域", "增加区域", "\\Demo.bmp");
rpedit.Source.Items.Add(rbaddpoint);
rpedit.Source.Items.Add(rbaddpolyline);
rpedit.Source.Items.Add(rbaddpolygon);
rtedit.Panels.Add(rpedit);
rc.Tabs.Clear();
rc.Tabs.Add(rt);
rc.Tabs.Add(rtedit);
}
/// <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;
}
/// <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,string strbmp)
{
RibbonButton ribButton = new RibbonButton();
ribButton.Text = btName;
ribButton.CommandParameter = cmdName;
ribButton.ShowText = true;
ribButton.LargeImage = new System.Windows.Media.Imaging.BitmapImage(new System.Uri(System.Windows.Forms.Application.StartupPath +strbmp));
ribButton.Size = Autodesk.Windows.RibbonItemSize.Large;
ribButton.ShowImage = 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?
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
RibbonButton ribBtn = parameter as RibbonButton;
if (ribBtn != null)
{
if ((String)ribBtn.CommandParameter == "系统退出")
Autodesk.AutoCAD.ApplicationServices.Application.Quit();
else if((String)ribBtn.CommandParameter == "数据加载")
doc.SendStringToExecute("COSQL ", true, false, false);
else
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.SendStringToExecute((String)ribBtn.CommandParameter, true, false, true);
//MessageBox.Show((String)ribBtn.CommandParameter);
}
//Autodesk.AutoCAD.ApplicationServices.Application.Quit();// Autodesk.AutoCAD.ApplicationServices.Application.MainWindow.Text = "CGBridge"; 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);
MessageBox.Show("fff");
}
}
}
}
第2个菜单不能激活 如何修改?
|
|