■ DiagramStencil 클래스의 RegisterTool 메소드를 사용해 스텐실에 커스텀 다이어그램 항목을 추가하는 방법을 보여준다.
▶ Status.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
namespace TestProject { /// <summary> /// 상태 /// </summary> public enum Status { /// <summary> /// 활성 /// </summary> Active, /// <summary> /// 비활성 /// </summary> Inactive } } |
▶ 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 |
using System.ComponentModel; using DevExpress.Utils.Serializing; using DevExpress.XtraDiagram; namespace TestProject { /// <summary> /// 커스텀 다이어그램 도형 /// </summary> public class CustomDiagramShape : DiagramShape { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 상태 - Status /// <summary> /// 상태 /// </summary> [Category("Info")] [XtraSerializableProperty] public Status Status { get; set; } #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 |
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(); DiagramControl.ItemTypeRegistrator.Register(typeof(CustomDiagramShape)); DiagramStencil stencil = new DiagramStencil("customShapes", "Custom Shapes"); stencil.RegisterTool ( new FactoryItemTool ( "activeTaskShape", () => "Active Task", diagram => new CustomDiagramShape { Content = "Active Task", Status = Status.Active }, new System.Windows.Size(150, 100), false ) ); stencil.RegisterTool ( new FactoryItemTool ( "inactiveTaskShape", () => "Inactive Task", diagram => new CustomDiagramShape { Content = "Inactive Task", Status = Status.Inactive }, new System.Windows.Size(150, 100), false ) ); DiagramToolboxRegistrator.RegisterStencil(stencil); this.diagramControl.OptionsBehavior.SelectedStencils = StencilCollection.Parse("customShapes"); CustomDiagramShape shape = new CustomDiagramShape(); shape.Size = new SizeF(100F, 100F); shape.Position = new PointFloat(300f, 300f); shape.Appearance.BorderSize = 4; shape.Appearance.BorderColor = Color.FromArgb(128, 0, 0, 0); shape.Appearance.BackColor = Color.White; shape.Appearance.Font = new Font("나눔고딕코딩", 12f, FontStyle.Bold); shape.Appearance.ForeColor = Color.FromArgb(128, 0, 0, 0); shape.Content = "도형"; shape.Status = Status.Active; this.diagramControl.Items.Add(shape); } #endregion } } |