CustomControlToolBoxRegistrator.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System.Drawing.Design;
  2. using CustomControls.Pattern;
  3. using DevExpress.XtraReports.UI;
  4. using DevExpress.XtraReports.UserDesigner;
  5. namespace CustomControls.Design
  6. {
  7. /// <summary>
  8. /// 注册控件
  9. /// </summary>
  10. public class CustomControlToolBoxRegistrator
  11. {
  12. public static void EnsurePatternControl(XRDesignMdiController designMdiController)
  13. {
  14. CustomControl.EnsurePatternBrick();
  15. AddPatternControlToToolBox(designMdiController);
  16. }
  17. /// <summary>
  18. /// 添加排花控件到控件库
  19. /// </summary>
  20. public static void AddPatternControlToToolBox(XRDesignMdiController designMdiController)
  21. {
  22. AddControlToToolBox<XRPattern>(designMdiController, "Pattern");
  23. }
  24. /// <summary>
  25. /// 添加控件到控件库
  26. /// </summary>
  27. private static void AddControlToToolBox<TControl>(XRDesignMdiController designMdiController, string displayName) where TControl : XRControl
  28. {
  29. designMdiController.DesignPanelLoaded += (s, e) =>
  30. {
  31. /* 获取工具箱服务 */
  32. var toolboxService = (IToolboxService)e.DesignerHost.GetService(typeof(IToolboxService));
  33. /* 将控件添加到工具箱 */
  34. var toolboxItem = new ToolboxItem(typeof(TControl)) { DisplayName = displayName };
  35. toolboxService.AddToolboxItem(toolboxItem);
  36. };
  37. }
  38. }
  39. }