c# cad二次开发 ribbon界面 给CAD加个菜单栏

c# cad二次开发 ribbon界面 给CAD加个菜单栏

using System;
using System.Collections.Generic;
using System.Text;
using System.Text;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using System.Linq;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.Windows;
using Autodesk.AutoCAD.GraphicsInterface;
using System.Windows.Media.Imaging;
using Autodesk.Internal.Windows;
using System.IO;
using static Autodesk.AutoCAD.Internal.LayoutContextMenu;

namespace _9_ribbon界面
{
public class ProgramClass
{
[CommandMethod(“yerb”)]
public void yerb()
{
//获取当前程序所在的文件路径
curpath.curPath = Path.GetDirectoryName(this.GetType().Assembly.Location) + “\”;

        RibbonControl ribbonctrl = ComponentManager.Ribbon;
        RibbonTab tab = ribbonctrl.addtab("DK", "ACAD.DK", true);
        RibbonPanelSource panlsource = tab.addpanel("绘图");
        RibbonButton btn = new RibbonButton();
        btn.Text = "直线";//按钮名称
        btn.Name = "直线";//按钮的提示信息
        btn.ShowText = true;//设置按钮名称可见
        //
        //设置按钮图标
        string imgname = curpath.curPath + "image\\back alt.ico";
        Uri uri = new Uri(imgname);
        BitmapImage img = new BitmapImage(uri);
        btn.Image = img;//按钮图片
        btn.LargeImage = img;//按钮大图片
        btn.ShowImage = true;//显示图片
        btn.Size = RibbonItemSize.Large;//按钮尺寸
        btn.Orientation = System.Windows.Controls.Orientation.Vertical;//按钮排列方式
        btn.MouseEntered += Btn_MouseEntered;//调用鼠标进入事件
        btn.MouseLeft += Btn_MouseLeft;//调用鼠标退出事件
        
        //设置按钮提示信息
        RibbonToolTip toolTip = new RibbonToolTip();
        toolTip.Title = "直线";
        toolTip.Content = "创建直线段";
        toolTip.Command = "Line";
        toolTip.ExpandedContent = "使用line命令,创建直线段";
        string imgname1 = curpath.curPath + "image\\k1.ico";
        Uri uri1 = new Uri(imgname1);
        BitmapImage img1 = new BitmapImage(uri1);
        toolTip.ExpandedImage = img1;
        btn.ToolTip = toolTip;
        /
        ///按钮关联命令
        btn.CommandHandler = new RibbonCommandHandler();
        btn.CommandParameter = "LIne ";//点击按钮执行命令
        panlsource.Items.Add(btn);
    }
    /// 
    /// 鼠标退出按钮事件
    /// 
    /// 
    /// 
    private void Btn_MouseLeft(object sender, EventArgs e)
    {
        RibbonButton btn = (RibbonButton)sender;
        string imgname = curpath.curPath + "image\\back alt.ico";
        Uri uri = new Uri(imgname);
        BitmapImage img = new BitmapImage(uri);
        btn.Image = img;//按钮图片
        btn.LargeImage = img;//按钮大图片
    }

    /// 
    /// 鼠标进入按钮事件
    /// 
    /// 
    /// 
    /// 
    private void Btn_MouseEntered(object sender, EventArgs e)
    {   
        RibbonButton btn = (RibbonButton)sender;
        //设置按钮图标
        string imgname = curpath.curPath + "image\\forward alt.ico";
        Uri uri = new Uri(imgname);
        BitmapImage img = new BitmapImage(uri);
        btn.Image = img;//按钮图片
        btn.LargeImage = img;//按钮大图片
    }
}

}


你可能感兴趣的:(c#,ribbon,linq)