■ DiagramControl 클래스의 CustomGetEditableItemProperties 이벤트를 사용해 속성 패널에 파생 도형 속성을 추가하는 방법을 보여준다.
▶ CustomDiagramShape.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
using DevExpress.Utils.Serializing; using DevExpress.XtraDiagram; namespace TestProject { /// <summary> /// 커스텀 다이어그램 도형 /// </summary> public class CustomDiagramShape : DiagramShape { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 데이터베이스 객체 ID - DatabaseObjectID /// <summary> /// 데이터베이스 객체 ID /// </summary> [XtraSerializableProperty] public int DatabaseObjectID { get; set; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Static #region 생성자 - CustomDiagramShape() /// <summary> /// 생성자 /// </summary> static CustomDiagramShape() { DiagramControl.ItemTypeRegistrator.Register(typeof(CustomDiagramShape)); } #endregion } } |
▶ MainForm.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
using System.ComponentModel; using System.Drawing; using DevExpress.Diagram.Core; using DevExpress.Utils; using DevExpress.XtraEditors; using DevExpress.XtraDiagram; namespace TestProject { /// <summary> /// 메인 폼 /// </summary> public partial class MainForm : XtraForm { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainForm() /// <summary> /// 생성자 /// </summary> public MainForm() { InitializeComponent(); DiagramStencil stencil = new DiagramStencil("CustomStencil", "Custom Shapes"); FactoryItemTool itemTool = new FactoryItemTool ( "CustomShape", () => "Custom Shape", diagram => { CustomDiagramShape customShape = new CustomDiagramShape() { Width = 100, Height = 50 }; return customShape; }, new System.Windows.Size(100, 50), false ); stencil.RegisterTool(itemTool); DiagramToolboxRegistrator.RegisterStencil(stencil); this.diagramControl.SelectedStencils = new StencilCollection("CustomStencil"); CustomDiagramShape shape = new CustomDiagramShape(); shape.Size = new SizeF(100f, 100f); shape.Position = new PointFloat(250f, 100f); shape.Content = "도형"; shape.DatabaseObjectID = 10; this.diagramControl.Items.Add(shape); this.diagramControl.CustomGetEditableItemProperties += diagramControl_CustomGetEditableItemProperties; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region 다이어그램 컨트롤 편집 가능한 항목 속성 커스텀 구하기 - diagramControl_CustomGetEditableItemProperties(sender, e) /// <summary> /// 다이어그램 컨트롤 편집 가능한 항목 속성 커스텀 구하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void diagramControl_CustomGetEditableItemProperties(object sender, DiagramCustomGetEditableItemPropertiesEventArgs e) { if(e.Item is CustomDiagramShape) { e.Properties.Add(TypeDescriptor.GetProperties(typeof(CustomDiagramShape))["DatabaseObjectID"]); } } #endregion } } |