첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
본 블로그는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 블로그 콘텐츠 향상을 위해 쓰여집니다.

728x90
반응형
728x170

TestProject.zip
다운로드

▶ MainForm.cs

using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Windows.Forms;

using Lassalle.Flow;

namespace TestProject
{
    /// <summary>
    /// 메인 폼
    /// </summary>
    public partial class MainForm : Form
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - MainForm()

        /// <summary>
        /// 생성자
        /// </summary>
        public MainForm()
        {
            InitializeComponent();

            CreateDiagram(this.addFlow);

            this.addFlow.SelectionChange += addFlow_SelectionChange;
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Private
        //////////////////////////////////////////////////////////////////////////////// Event

        #region AddFlow 선택 변경시 처리하기 - addFlow_SelectionChange(sender, e)

        /// <summary>
        /// AddFlow 선택 변경시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void addFlow_SelectionChange(object sender, SelectionChangeArgs e)
        {
            AddFlow addFlow = sender as AddFlow;

            Node[] nodeArray = addFlow.Items.OfType<Node>().ToArray();

            foreach(Node node in nodeArray)
            {
                if(node.IsSelected)
                {
                    node.DrawColor = Color.Red;
                    node.Thickness = 3;
                }
                else
                {
                    node.DrawColor = this.addFlow.NodeModel.DrawColor;
                    node.Thickness = this.addFlow.NodeModel.Thickness;
                }
            }
        }


        #endregion

        //////////////////////////////////////////////////////////////////////////////// Function

        #region 노드 추가하기 - AddNode(addflow, left, top, width, height, flag, text)

        /// <summary>
        /// 노드 추가하기
        /// </summary>
        /// <param name="addflow">AddFlow</param>
        /// <param name="left">왼쪽 좌표</param>
        /// <param name="top">위쪽 좌표</param>
        /// <param name="width">너비</param>
        /// <param name="height">높이</param>
        /// <param name="flag">플래그</param>
        /// <param name="text">텍스트</param>
        /// <returns>노드</returns>
        Node AddNode(AddFlow addflow, float left, float top, float width, float height, bool flag, string text)
        {
            Node node = new Node(left, top, width, height, text, addflow);

            if(flag)
            {
                node.FillColor = Color.Yellow;
            }

            addflow.AddNode(node);

            return node;
        }

        #endregion
        #region 링크 추가하기 - AddLink(addFlow, startNode, endNode)

        /// <summary>
        /// 링크 추가하기
        /// </summary>
        /// <param name="addFlow">AddFlow</param>
        /// <param name="startNode">시작 노드</param>
        /// <param name="endNode">종료 노드</param>
        /// <returns>링크</returns>
        Link AddLink(AddFlow addFlow, Node startNode, Node endNode)
        {
            Link link = new Link(startNode, endNode, null, addFlow);

            addFlow.AddLink(link);

            return link;
        }

        #endregion

        #region 다이어그램 생성하기 - CreateDiagram(addFlow)

        /// <summary>
        /// 다이어그램 생성하기
        /// </summary>
        /// <param name="addFlow">AddFlow</param>
        private void CreateDiagram(AddFlow addFlow)
        {
            addFlow.BackColor                  = SystemColors.Window;
            addFlow.PageUnit                   = GraphicsUnit.Pixel;
            addFlow.CanMoveItems               = false;
            addFlow.CanDrawLink                = false;
            addFlow.CanDrawNode                = false;
            addFlow.CanSizeItems               = false;
            addFlow.CanMultiSelect             = false;
            addFlow.CanEditContentItem         = false;
            addFlow.IsSelectionHandleDisplayed = false;

            addFlow.NodeModel.GradientMode = LinearGradientMode.Horizontal;
            addFlow.NodeModel.FillColor    = Color.White;
            addFlow.NodeModel.ShapeFamily  = ShapeFamily.Rectangle;
            addFlow.NodeModel.ShadowStyle  = ShadowStyle.RightBottom;
            addFlow.NodeModel.ShadowColor  = Color.Silver;
            addFlow.NodeModel.ShadowSize   = new Size(2, 2);

            addFlow.LinkModel.IsArrowDst   = false;
            addFlow.LinkModel.LineStyle    = LineStyle.VHV;
            addFlow.LinkModel.DrawColor    = Color.Black;
            addFlow.LinkModel.Thickness    = 2;
            addFlow.LinkModel.IsSelectable = false;

            // 캡션을 생성한다.
            Lassalle.Flow.Caption caption = new Lassalle.Flow.Caption(100, 60, 200, 20, "부르봉 왕가", null, addFlow);

            caption.DrawColor    = Color.Transparent;
            caption.TextColor    = Color.Orange;
            caption.IsSelectable = false;
            caption.Font         = new Font("나눔고딕코딩", 16f);

            addFlow.AddCaption(caption);

            // 노드들을 생성한다.
            this.AddNode(addFlow, 350, 20 , 160, 50, false, "Antoine de Bourbon\r\n1518-1562"                          );
            this.AddNode(addFlow, 350, 85 , 160, 50, true , "Henry IV\r\n1553-1569-1610"                               );
            this.AddNode(addFlow, 350, 150, 160, 50, true , "Louis XIII\r\n1601-1610-1643"                             );
            this.AddNode(addFlow, 180, 215, 160, 50, true , "Louis XIV dit le Grand\r\n1638-1643-1715"                 );
            this.AddNode(addFlow, 180, 280, 160, 50, false, "Louis de France\r\nGrand Dauphin\r\n1661-1711"            );
            this.AddNode(addFlow, 180, 345, 160, 50, false, "Louis de France\r\nDauphin\r\n1682-1712"                  );
            this.AddNode(addFlow, 180, 410, 160, 50, true , "Louis XV\r\n1710-1715-1774"                               );
            this.AddNode(addFlow, 180, 475, 160, 50, false, "Louis de France\r\nDauphin\r\n1729-1765"                  );
            this.AddNode(addFlow, 10 , 540, 160, 50, true , "Louis XVI\r\n1754-1774-1792-1793"                         );
            this.AddNode(addFlow, 10 , 600, 160, 50, false, "Louis XVII\r\n1785-1795?"                                 );
            this.AddNode(addFlow, 180, 540, 160, 50, true , "Louis XVIII\r\n1755-1814-1824"                            );
            this.AddNode(addFlow, 350, 540, 160, 50, true , "Charles X\r\n1757-1824-1830-1836"                         );
            this.AddNode(addFlow, 520, 215, 160, 50, false, "Philippe d'Orléans\r\n1640-1701"                           );
            this.AddNode(addFlow, 520, 280, 160, 50, false, "Philippe II d'Orléans\r\n1674-1723"                        );
            this.AddNode(addFlow, 520, 345, 160, 50, false, "Louis d'Orléans\r\n1703-1752"                              );
            this.AddNode(addFlow, 520, 410, 160, 50, false, "Louis-Philippe d'Orléans\r\n1725-1785"                     );
            this.AddNode(addFlow, 520, 475, 160, 50, false, "Louis-Philippe Joseph\r\ndit Philippe Egalité\r\n1743-1793");
            this.AddNode(addFlow, 520, 540, 160, 50, true , "Louis-Philippe\r\n1773-1830-1848-1850"                    );
            
            Node[] nodeArray = addFlow.Items.OfType<Node>().ToArray();

            this.AddLink(addFlow, nodeArray[0 ], nodeArray[1 ]);
            this.AddLink(addFlow, nodeArray[1 ], nodeArray[2 ]);
            this.AddLink(addFlow, nodeArray[2 ], nodeArray[3 ]);
            this.AddLink(addFlow, nodeArray[3 ], nodeArray[4 ]);
            this.AddLink(addFlow, nodeArray[4 ], nodeArray[5 ]);
            this.AddLink(addFlow, nodeArray[5 ], nodeArray[6 ]);
            this.AddLink(addFlow, nodeArray[6 ], nodeArray[7 ]);
            this.AddLink(addFlow, nodeArray[7 ], nodeArray[8 ]);
            this.AddLink(addFlow, nodeArray[8 ], nodeArray[9 ]);
            this.AddLink(addFlow, nodeArray[7 ], nodeArray[10]);
            this.AddLink(addFlow, nodeArray[7 ], nodeArray[11]);
            this.AddLink(addFlow, nodeArray[2 ], nodeArray[12]);
            this.AddLink(addFlow, nodeArray[12], nodeArray[13]);
            this.AddLink(addFlow, nodeArray[13], nodeArray[14]);
            this.AddLink(addFlow, nodeArray[14], nodeArray[15]);
            this.AddLink(addFlow, nodeArray[15], nodeArray[16]);
            this.AddLink(addFlow, nodeArray[16], nodeArray[17]);
        }

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

댓글을 달아 주세요