첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
유용한 소스 코드가 있으면 icodebroker@naver.com으로 보내주시면 감사합니다.
블로그 자료는 자유롭게 사용하세요.

■ DiagramToolboxRegistrator 클래스 : RegisterStencil/UnregisterStencil 정적 메소드를 사용해 스텐실 등록하기/등록 취소하기

------------------------------------------------------------------------------------------------------------------------


TestProject.zip


MainForm.cs

 

 

using System.Collections.Generic;

using System.Drawing;

using System.IO;

using System.Linq;

 

using DevExpress.Diagram.Core;

using DevExpress.Utils;

using DevExpress.XtraDiagram;

using DevExpress.XtraEditors;

 

namespace TestProject

{

    /// <summary>

    /// 메인 폼

    /// </summary>

    public partial class MainForm : XtraForm

    {

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor

        ////////////////////////////////////////////////////////////////////////////////////////// Public

 

        #region 생성자 - MainForm()

 

        /// <summary>

        /// 생성자

        /// </summary>

        public MainForm()

        {

            InitializeComponent();

 

            DiagramStencil diagramStencil = new DiagramStencil("SVGShape", "SVGShape");

 

            for(int i = 1; i < 6; i++)

            {

                string filePath = $"IMAGE\\chart{i}.svg";

 

                using(FileStream stream = File.OpenRead(filePath))

                {

                    ShapeDescription shapeDescription = ShapeDescription.CreateSvgShape($"chart{i}", $"chart{i}", stream);

 

                    diagramStencil.RegisterShape(shapeDescription);

                }

            }

 

            DiagramToolboxRegistrator.RegisterStencil(diagramStencil);

 

            for(int i = 0; i < 5; i++)

            {

                int x = GetColumnIndex(5, i);

                int y = GetRowIndex(5, i);

 

                DiagramShape shape = new DiagramShape();

 

                shape.Size     = new SizeF(100f, 100f);

                shape.Position = new PointFloat(x * 150f + 100f, y * 150f + 100f);

                shape.Shape    = diagramStencil.GetShape($"chart{i + 1}");

 

                this.diagramControl.Items.Add(shape);

            }

 

            this.diagramControl.FitToDrawing();

 

            List<DiagramStencil> stencilList = DiagramToolboxRegistrator.Stencils.ToList<DiagramStencil>();

 

            stencilList.ForEach(stencil => DiagramToolboxRegistrator.UnregisterStencil(stencil));

        }

 

        #endregion

 

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method

        ////////////////////////////////////////////////////////////////////////////////////////// Private

 

        #region 행 인덱스 구하기 - GetRowIndex(columnCount, sequenceIndex)

 

        /// <summary>

        /// 행 인덱스 구하기

        /// </summary>

        /// <param name="columnCount">컬럼 수</param>

        /// <param name="sequenceIndex">순번 인덱스</param>

        /// <returns>행 인덱스</returns>

        private int GetRowIndex(int columnCount, int sequenceIndex)

        {

            return sequenceIndex / columnCount;

        }

 

        #endregion

        #region 컬럼 인덱스 구하기 - GetColumnIndex(columnCount, sequenceIndex)

 

        /// <summary>

        /// 컬럼 인덱스 구하기

        /// </summary>

        /// <param name="columnCount">컬럼 수</param>

        /// <param name="sequenceIndex">순번 인덱스</param>

        /// <returns>컬럼 인덱스</returns>

        private int GetColumnIndex(int columnCount, int sequenceIndex)

        {

            return sequenceIndex % columnCount;

        }

 

        #endregion

    }

}

 

------------------------------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker
TAG

댓글을 달아 주세요