# 0. 引言
先看看結果,這裡添加了一個頁籤,在裡面仿照系統醫院添加了繪圖面闆和兩個按鈕操作,并将按鈕的操作功能也加了進行

當你不斷進步有自己的小算法可以往裡面添加的時候,就可以在裡面加入自己的東西了
# 1. 添加頁籤和面闆
頁籤就是下面這個東東
添加頁籤
RibbonTab tab = ribbonCtrl.AddTab("我的測試頁籤", "Acad.RibbonId1", true); //給Ribbon界面添加一個頁籤
AddTab方法封裝如下
添加面闆
這一塊就叫做面闆
RibbonPanelSource panelSource = tab.AddPanel("繪圖"); //給頁籤添加面闆
AddPanel方法封裝如下
# 2. 添加按鈕
按鈕裡面包括了文本、圖檔以及按鈕本身所附屬的功能操作
直線按鈕封裝
//直線按鈕
private static RibbonButtonEX lineBtn;
public static RibbonButtonEX LineBtn
{
get
{
lineBtn = new RibbonButtonEX("直線", RibbonItemSize.Large, Orientation.Vertical, "Line");
lineBtn.SetImg(CurPaht.curPaht + "Images\\Line.PNG");//設定按鈕圖檔
//添加提示對象
RibbonToolTip toolTip = new RibbonToolTip();
toolTip.Title = "直線";
toolTip.Content = "建立直線段";
toolTip.Command = "LINE";
toolTip.ExpandedContent = "是用LINE指令,可以建立一些列連續的直線段。每條線段都是可以單獨進行編輯的直線對象。";
string imgToolTipFileName = CurPaht.curPaht + "Images\\LineTooTip.PNG";
Uri toolTipUri = new Uri(imgToolTipFileName);
BitmapImage toolTipBitmapImge = new BitmapImage(toolTipUri);
toolTip.ExpandedImage = toolTipBitmapImge;
lineBtn.ToolTip = toolTip;
//滑鼠進入時的圖檔
lineBtn.ImgHoverFileName = CurPaht.curPaht + "Images\\LineHover.PNG";
return lineBtn;
}
}
多段線按鈕封裝
//多段線按鈕
private static RibbonButtonEX polylineBtn;
public static RibbonButtonEX PolylineBtn
{
get
{
polylineBtn = new RibbonButtonEX("多段線", RibbonItemSize.Large, Orientation.Vertical, "Pline");
polylineBtn.SetImg(CurPaht.curPaht + "Images\\Polyline.PNG");//設定按鈕圖檔
//添加提示對象
RibbonToolTip toolTip = new RibbonToolTip();
toolTip.Title = "多段線";
toolTip.Content = "建立二維多段線";
toolTip.Command = "PLINE";
toolTip.ExpandedContent = "二維多段線是作為單個平面對象建立的互相連接配接的線段序列。可以建立直線段、圓弧段或者兩者的組合線段。";
string imgToolTipFileName = CurPaht.curPaht + "Images\\PolylineToolTip.PNG";
Uri toolTipUri = new Uri(imgToolTipFileName);
BitmapImage toolTipBitmapImge = new BitmapImage(toolTipUri);
toolTip.ExpandedImage = toolTipBitmapImge;
polylineBtn.ToolTip = toolTip;
//滑鼠進入時的圖檔
polylineBtn.ImgHoverFileName = CurPaht.curPaht + "Images\\PolylineHover.PNG";
return polylineBtn;
}
}
将按鈕添加到面闆,上面按鈕都封裝到了類RibbonButtonInfos.cs中,添加即可
panelSource.Items.Add(RibbonButtonInfos.LineBtn); //添加直線指令按鈕
panelSource.Items.Add(RibbonButtonInfos.PolylineBtn); //添加多段線指令按鈕
完整代碼位址:https://gitee.com/yuzhaokai/cad_secondary_development_code.git
原文位址請關注公衆号:資料智能筆記