using System.Drawing.Design;
using CustomControls.Pattern;
using DevExpress.XtraReports.UI;
using DevExpress.XtraReports.UserDesigner;
namespace CustomControls.Design
{
///
/// 注册控件
///
public class CustomControlToolBoxRegistrator
{
public static void EnsurePatternControl(XRDesignMdiController designMdiController)
{
CustomControl.EnsurePatternBrick();
AddPatternControlToToolBox(designMdiController);
}
///
/// 添加排花控件到控件库
///
public static void AddPatternControlToToolBox(XRDesignMdiController designMdiController)
{
AddControlToToolBox(designMdiController, "Pattern");
}
///
/// 添加控件到控件库
///
private static void AddControlToToolBox(XRDesignMdiController designMdiController, string displayName) where TControl : XRControl
{
designMdiController.DesignPanelLoaded += (s, e) =>
{
/* 获取工具箱服务 */
var toolboxService = (IToolboxService)e.DesignerHost.GetService(typeof(IToolboxService));
/* 将控件添加到工具箱 */
var toolboxItem = new ToolboxItem(typeof(TControl)) { DisplayName = displayName };
toolboxService.AddToolboxItem(toolboxItem);
};
}
}
}