c# cad二次开发,给CAD界面添加ribbon控件,相当于一个菜单栏

c# cad二次开发,给CAD界面添加ribbon控件,相当于一个菜单栏
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;//按钮大图片
}

    /// <summary>
    /// 鼠标进入按钮事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    /// <exception cref="NotImplementedException"></exception>
    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;//按钮大图片
    }
}

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

DK业

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值