첨부 소스 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

TestProject.zip
다운로드

▶ Status.cs

namespace TestProject
{
    /// <summary>
    /// 상태
    /// </summary>
    public enum Status
    {
        /// <summary>
        /// 활성
        /// </summary>
        Active,
        
        /// <summary>
        /// 비활성
        /// </summary>
        Inactive
    }
}

 

728x90

 

▶ CustomDiagramShape.cs

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
    }
}

 

300x250

 

▶ MainForm.cs

using System.ComponentModel;
using System.Drawing;

using DevExpress.Diagram.Core;
using DevExpress.Images;
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraDiagram;

namespace TestProject
{
    /// <summary>
    /// 메인 폼
    /// </summary>
    public partial class MainForm : RibbonForm
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// 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");

            this.diagramControl.CreateRibbon();

            this.diagramControl.CreateDocking();

            this.diagramControl.CustomGetEditableItemProperties += diagramControl_CustomGetEditableItemProperties;
            this.diagramControl.CustomDrawItem                  += diagramControl_CustomDrawItem;
        }

        #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)
        {
            e.Properties.Add(TypeDescriptor.GetProperties(typeof(CustomDiagramShape))["Status"]);
        }

        #endregion
        #region 다이어그램 컨트롤 항목 커스텀 그리기 - diagramControl_CustomDrawItem(sender, e)

        /// <summary>
        /// 다이어그램 컨트롤 항목 커스텀 그리기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void diagramControl_CustomDrawItem(object sender, CustomDrawItemEventArgs e)
        {
            CustomDiagramShape shape = e.Item as CustomDiagramShape;

            if(shape == null)
            {
                return;
            }

            e.DefaultDraw();

            string imageFilePath = shape.Status == Status.Active ? "images/actions/apply_16x16.png" : "images/actions/cancel_16x16.png";

            Image image = ImageResourceCache.Default.GetImage(imageFilePath);

            float margin = 3f;

            e.Graphics.DrawImage
            (
                image,
                new RectangleF
                (
                    shape.Width  - image.Width  - margin,
                    shape.Height - image.Height - margin,
                    image.Width,
                    image.Height
                )
            );

            e.Handled = true;
        }

        #endregion
    }
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요