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

■ DiagramControl 클래스 : SVG 도형 사용하기

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


TestProject.zip


MainForm.cs

 

 

using System.IO;

 

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 stencil = new DiagramStencil("SVGStencil", "SVGStencil");

 

            string fileNameWithoutExtension = null;

 

            foreach(string filePath in Directory.GetFiles("IMAGE"))

            {

                try

                {

                    fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(filePath);

 

                    using(FileStream stream = File.Open(filePath, FileMode.Open))

                    {

                        ShapeDescription shapeDescription = ShapeDescription.CreateSvgShape

                        (

                            fileNameWithoutExtension,

                            fileNameWithoutExtension,

                            stream

                        )

                        .Update(getDefaultSize      : () => new System.Windows.Size(100, 100))

                        .Update(getConnectionPoints : (w, h, p) => new[] { new System.Windows.Point(w / 2, h / 2) });

 

                        stencil.RegisterShape(shapeDescription);

                    }

                }

                catch

                {

                }

            }

 

            DiagramToolboxRegistrator.RegisterStencil(stencil);

 

            this.diagramControl.SelectedStencils.Add("SVGStencil");

 

            this.diagramControl.Items.Add

            (

                new DiagramShape()

                {

                    Shape    = stencil.GetShape("aid-kit"),

                    Width    = 100,

                    Height   = 100,

                    Position = new PointFloat(400, 300)

                }

            );

        }

 

        #endregion

    }

}

 

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

Posted by 사용자 icodebroker
TAG

댓글을 달아 주세요