123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- using System.Drawing.Design;
- using CustomControls.Pattern;
- using DevExpress.XtraReports.UI;
- using DevExpress.XtraReports.UserDesigner;
- namespace CustomControls.Design
- {
- /// <summary>
- /// 注册控件
- /// </summary>
- public class CustomControlToolBoxRegistrator
- {
- public static void EnsurePatternControl(XRDesignMdiController designMdiController)
- {
- CustomControl.EnsurePatternBrick();
- AddPatternControlToToolBox(designMdiController);
- }
- /// <summary>
- /// 添加排花控件到控件库
- /// </summary>
- public static void AddPatternControlToToolBox(XRDesignMdiController designMdiController)
- {
- AddControlToToolBox<XRPattern>(designMdiController, "Pattern");
- }
- /// <summary>
- /// 添加控件到控件库
- /// </summary>
- private static void AddControlToToolBox<TControl>(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);
- };
- }
- }
- }
|