■ AddFlow 클래스에서 가계도를 표시하는 방법을 보여준다.
▶ 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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
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 } } |