当前位置:编程学习 > C#/ASP.NET >>

用C#生成Revit按钮

首先添加大图标和小图标到项目中,然后设置成嵌入资源,下列代码就可以生成这个按钮并调用定义的命令啦:



private RibbonPanel CreateRibbonPanel()

{

    RibbonPanel panel = _cachedUiCtrApp.CreateRibbonPanel("RevitAddinCS");

 

    PushButtonData pbDataExtCmd = new PushButtonData("ExtCmd", "ExtCmd", Assembly.GetExecutingAssembly().Location, "RevitAddinCS.ExtCmd");

    PushButton pbExtCmd = panel.AddItem(pbDataExtCmd) as PushButton; 

    pbExtCmd.ToolTip = "ExtCmd";

    pbExtCmd.LargeImage = BmpImageSource("RevitAddinCS.Resources.ExtCmd32x32.bmp");

    pbExtCmd.Image = BmpImageSource("RevitAddinCS.Resources.ExtCmd16x16.bmp");

 

    return panel;

}

 

private System.Windows.Media.ImageSource BmpImageSource(string embeddedPath)

{

    Stream stream = this.GetType().Assembly.GetManifestResourceStream(embeddedPath);

    var decoder = new System.Windows.Media.Imaging.BmpBitmapDecoder(stream,  BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);

    

    return decoder.Frames[0];

}
--------------------编程问答-------------------- 不错不错!
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,