我已在Modify
标签下的Properties
标签下创建了一个添加到Revit功能区的按钮。按钮显示和功能没有问题。我们遇到的唯一问题是按钮的图标不会显示。我们已经尝试了几种方法来解决这个问题,但似乎没有任何效果。
Autodesk.Windows.RibbonControl pRibbon = Autodesk.Windows.ComponentManager.Ribbon;
foreach (var pTab in pRibbon.Tabs)
{
if (pTab.Id == "Modify")
{
foreach (var pPanel in pTab.Panels)
{
if (pPanel.Source.Id == "properties_shr")
{
// Add button.
pIcon = Properties.Resources.AS_Revit_UI_Taps_Tees32x32.GetHbitmap();
var pBtn = CreatePanelButton(pIcon, "Taps/Tees", "id_astapteebutton", "Taps/Tees", 32, 32);
Autodesk.Windows.ComponentManager.UIElementActivated += RunSwitchTapTee;
pPanel.Source.Items.Add(pBtn);
break;
}
}
}
}
public Autodesk.Windows.RibbonButton CreatePanelButton(IntPtr pIcon, string sBtnName, string sID, string sText, int iHeight, int iWidth)
{
var pBtn = new Autodesk.Windows.RibbonButton()
{
Name = sBtnName,
Image = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(pIcon, IntPtr.Zero, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromWidthAndHeight(32, 32)),
Id = sID,
AllowInStatusBar = true,
AllowInToolBar = true,
GroupLocation = Autodesk.Private.Windows.RibbonItemGroupLocation.Middle,
MinHeight = 0,
MinWidth = 0,
Height = iHeight,
Width = iWidth,
IsEnabled = true,
IsVisible = true,
IsCheckable = true,
ShowImage = true,
ShowText = true,
Orientation = System.Windows.Controls.Orientation.Vertical,
Text = sText,
Size = Autodesk.Windows.RibbonItemSize.Large,
ResizeStyle = Autodesk.Windows.RibbonItemResizeStyles.HideText
};
return pBtn;
}
结果如下:
如您所见,按钮已放置。它按预期工作。它只是不会显示图标...任何帮助将不胜感激。感谢。
答案 0 :(得分:1)
我发现我的错误是在Image
的设置中。我写道:
Image = System.Windows.Interop....
.
.
.
Size = Autodesk.Windows.RibbonItemSize.Large,
我需要调整其中一个 - Image
到LargeImage
或 RibbonItemSize.Large
到RibbonItemSize.Standard
...
大图像需要大尺寸才有意义,标准图像需要标准尺寸。
在Revit中,功能区按钮可以是16x16像素(标准)或32x32像素(大)。根据您所需的UI布局,将帮助您确定所需的内容。