■ DiagramControl 클래스를 사용해 연결 포인트를 갖는 커스텀 도형을 생성하는 방법을 보여준다.
▶ CustomShape.xml
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 |
<?xml version="1.0"?> <Shapes xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <ShapeTemplate Id="Shape1" DefaultSize="50,100" Rows="*" Columns="*"> <Start X="0" Y="0" /> <Line X="1" Y="0" /> <Line X="0.8" Y="0.8" /> <Line X="0" Y="1" /> <ConnectionPoints> <ShapePoint X="0" Y="0" /> <ShapePoint X="0.5" Y="0" /> <ShapePoint X="1" Y="0" /> <ShapePoint X="0.8" Y="0.8" /> <ShapePoint X="0" Y="1" /> <ShapePoint X="0" Y="0.5" /> </ConnectionPoints> <Parameters /> </ShapeTemplate> <ShapeTemplate Id="Shape2" DefaultSize="60,120" Rows="*" Columns="*"> <Start X="0" Y="0" FillColor="Brown" /> <Arc X="1" Y="0" Size="CreateSize([W] / 2 , [H] / 10)" /> <Arc X="1" Y="1" Size="CreateSize([W] / 10, [H] / 2 )" /> <Arc X="0" Y="1" Size="CreateSize([W] / 2 , [H] / 10)" /> <Arc X="0" Y="0" Size="CreateSize([W] / 10, [H] / 2 )" /> <ConnectionPoints> <ShapePoint X="0" Y="0" /> <ShapePoint X="1" Y="0" /> <ShapePoint X="0" Y="1" /> </ConnectionPoints> <Parameters /> </ShapeTemplate> <ShapeTemplate Id="Shape3" DefaultSize="60,120" Rows="*" Columns="*"> <Start X="0" Y="0" FillColor="Brown" /> <Arc X="1" Y="0" Size="CreateSize([W] / 2, [P0] * [H])" /> <Line X="1" Y="1" /> <Line X="0" Y="1" /> <Line X="0" Y="0" /> <ConnectionPoints> <ShapePoint X="0" Y="0" /> <ShapePoint X="1" Y="0" /> <ShapePoint X="0" Y="1" /> </ConnectionPoints> <Parameters> <Parameter DefaultValue="0.1" Value="[P.Y] / [H]" Point="CreatePoint([W] / 2, [P] * [H])" Min="0" Max="1" /> </Parameters> </ShapeTemplate> <ShapeTemplate Id="Shape4" DefaultSize="60,120" IsQuick="true" Rows="[H] * [P0];[H] * (1 - [P0])" Columns="*"> <Start X="0" Y="0" FillColor="Green" /> <Line X="1" Y="0" /> <Line X="1" Y="1" /> <Line X="0" Y="1" /> <Start X="0" Y="1" FillColor="Red" /> <Line X="1" Y="1" /> <Line X="1" Y="2" /> <Line X="0" Y="2" /> <ConnectionPoints> <ShapePoint X="0.5" Y="0" /> <ShapePoint X="1" Y="1" /> <ShapePoint X="0.5" Y="2" /> <ShapePoint X="0" Y="1" /> </ConnectionPoints> <Parameters> <Parameter DefaultValue="0.5" Value="[P.Y] / [H]" Point="CreatePoint([W], [P] * [H])" Min="0" Max="1" /> </Parameters> </ShapeTemplate> </Shapes> |
▶ 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 |
using System; using System.IO; using DevExpress.Diagram.Core; using DevExpress.XtraBars.Ribbon; namespace TestProject { /// <summary> /// 메인 폼 /// </summary> public partial class MainForm : RibbonForm { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainForm() /// <summary> /// 생성자 /// </summary> public MainForm() { InitializeComponent(); using(FileStream stream = new FileStream("CustomShape.xml", FileMode.Open)) { DiagramStencil stencil = DiagramStencil.Create("CustomShapes", "Custom Shapes", stream, shapeName => shapeName); DiagramToolboxRegistrator.RegisterStencil(stencil); } this.diagramControl.SelectedStencils = new StencilCollection(new string[] { "CustomShapes" }); } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Protected #region 폼 로드시 처리하기 - OnLoad(e) /// <summary> /// 폼 로드시 처리하기 /// </summary> /// <param name="e">이벤트 인자</param> protected override void OnLoad(EventArgs e) { base.OnLoad(e); this.diagramControl.InitializeRibbon(this.ribbonControl); } #endregion } } |