我以这种方式添加了一个托管 winform 控件的调色板:
using System.Windows.Forms;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Windows;
namespace AMU.AutoCAD.BlockTool
{
public class MyPalette : IExtensionApplication
{
private PaletteSet palette;
private Control paletteControl;
public void Initialize()
{
//This is called when AutoCAD loads your assembly
this.palette = new PaletteSet("Name")
{
TitleBarLocation = PaletteSetTitleBarLocation.Left,
Style = PaletteSetStyles.Snappable //Your Styles
};
this.paletteControl = new Control(); //Instance of your Control that will be visible in AutoCAD
this.palette.Add("HEADER", this.paletteControl);
this.palette.Visible = true;
}
public void Terminate()
{
//cleanup
this.palette.Dispose();
this.paletteControl.Dispose();
}
}
}
通过提供实现 IExtensionApplication 的类,您可以在加载 dll 时执行自定义代码,而无需显式调用方法。您现在可以创建一个所谓的 PaletteSet 并向其添加 Winform 或 WPF 控件。