# diagram-org-chart-layout

> Diagram that renders an organization chart with hierarchical node positioning, parent child connectors and per role styling.

**Framework:** winforms  **Component:** Diagram  **Variant:** org-chart-layout

## Get this item

**If you are an agent, fetch the JSON.** Source is inlined, so one request is enough and no tooling is required:

```
GET https://ai.syncfusion.com/r/winforms/diagram-org-chart-layout.json
```

**Install Package(s)**

```bash
dotnet add package Syncfusion.Diagram.Windows
```

**Notes**

- Syncfusion release: 2026 Volume 3 (v35.1.37)
- The Syncfusion package is licensed. The composition in this file is source you own and edit. See https://ai.syncfusion.com/licensing.md

## Source files

### src/components/diagram-org-chart-layout/diagram.Designer.cs

```cs
namespace OrgChartLayout
{
    public partial class Form1
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            this.panel2 = new System.Windows.Forms.Panel();
            this.expanderPanel2 = new System.Windows.Forms.Panel();
            this.bShape = new System.Windows.Forms.Label();
            this.expSymShapeLbl = new System.Windows.Forms.Label();
            this.comboBShape = new System.Windows.Forms.ComboBox();
            this.comboExpSymbol = new System.Windows.Forms.ComboBox();
            this.expanderPanel1 = new System.Windows.Forms.Panel();
            this.label1 = new System.Windows.Forms.Label();
            this.vSpacing = new System.Windows.Forms.Label();
            this.hSpacing = new System.Windows.Forms.Label();
            this.apply = new System.Windows.Forms.Button();
            this.txtHSpacing = new System.Windows.Forms.TextBox();
            this.chkAutoLayout = new System.Windows.Forms.CheckBox();
            this.txtVSpacing = new System.Windows.Forms.TextBox();
            this.txtTMarigin = new System.Windows.Forms.TextBox();
            this.lMarigin = new System.Windows.Forms.Label();
            this.tMarigin = new System.Windows.Forms.Label();
            this.txtLMarigin = new System.Windows.Forms.TextBox();
            this.lytTypLbl = new System.Windows.Forms.Label();
            this.comboLytType = new System.Windows.Forms.ComboBox();
            this.diagram1 = new Syncfusion.Windows.Forms.Diagram.Controls.Diagram(this.components);
            this.model1 = new Syncfusion.Windows.Forms.Diagram.Model(this.components);
            this.lytProp = new System.Windows.Forms.Label();
            this.label2 = new System.Windows.Forms.Label();
            this.panel2.SuspendLayout();
            this.expanderPanel2.SuspendLayout();
            this.expanderPanel1.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.diagram1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.model1)).BeginInit();
            this.SuspendLayout();
            // 
            // panel2
            // 
            this.panel2.Controls.Add(this.expanderPanel2);
            this.panel2.Controls.Add(this.expanderPanel1);
            this.panel2.Dock = System.Windows.Forms.DockStyle.Right;
            this.panel2.Location = new System.Drawing.Point(751, 2);
            this.panel2.Name = "panel2";
            this.panel2.Size = new System.Drawing.Size(279, 607);
            this.panel2.TabIndex = 2;
            // 
            // expanderPanel2
            // 
            this.expanderPanel2.BackColor = System.Drawing.Color.White;
            this.expanderPanel2.Controls.Add(this.label2);
            this.expanderPanel2.Controls.Add(this.bShape);
            this.expanderPanel2.Controls.Add(this.expSymShapeLbl);
            this.expanderPanel2.Controls.Add(this.comboBShape);
            this.expanderPanel2.Controls.Add(this.comboExpSymbol);
            this.expanderPanel2.Dock = System.Windows.Forms.DockStyle.Fill;
            this.expanderPanel2.Location = new System.Drawing.Point(0, 344);
            this.expanderPanel2.Name = "expanderPanel2";
            this.expanderPanel2.Padding = new System.Windows.Forms.Padding(10, 10, 10, 10);
            this.expanderPanel2.Size = new System.Drawing.Size(279, 263);
            this.expanderPanel2.TabIndex = 1;
            // 
            // bShape
            // 
            this.bShape.AutoSize = true;
            this.bShape.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.bShape.Location = new System.Drawing.Point(13, 55);
            this.bShape.Name = "bShape";
            this.bShape.Size = new System.Drawing.Size(106, 15);
            this.bShape.TabIndex = 3;
            this.bShape.Text = "Background Shape";
            // 
            // expSymShapeLbl
            // 
            this.expSymShapeLbl.AutoSize = true;
            this.expSymShapeLbl.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.expSymShapeLbl.Location = new System.Drawing.Point(13, 91);
            this.expSymShapeLbl.Name = "expSymShapeLbl";
            this.expSymShapeLbl.Size = new System.Drawing.Size(82, 15);
            this.expSymShapeLbl.TabIndex = 5;
            this.expSymShapeLbl.Text = "Symbol Shape";
            // 
            // comboBShape
            // 
            this.comboBShape.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
            this.comboBShape.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.comboBShape.FormattingEnabled = true;
            this.comboBShape.Items.AddRange(new object[] {
            "Rectangle",
            "Ellipse"});
            this.comboBShape.Location = new System.Drawing.Point(151, 52);
            this.comboBShape.Name = "comboBShape";
            this.comboBShape.Size = new System.Drawing.Size(104, 23);
            this.comboBShape.TabIndex = 2;
            // 
            // comboExpSymbol
            // 
            this.comboExpSymbol.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
            this.comboExpSymbol.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.comboExpSymbol.FormattingEnabled = true;
            this.comboExpSymbol.Items.AddRange(new object[] {
            "Triangle",
            "PlusMinus"});
            this.comboExpSymbol.Location = new System.Drawing.Point(151, 88);
            this.comboExpSymbol.Name = "comboExpSymbol";
            this.comboExpSymbol.Size = new System.Drawing.Size(104, 23);
            this.comboExpSymbol.TabIndex = 4;
            // 
            // expanderPanel1
            // 
            this.expanderPanel1.BackColor = System.Drawing.Color.White;
            this.expanderPanel1.Controls.Add(this.lytProp);
            this.expanderPanel1.Controls.Add(this.label1);
            this.expanderPanel1.Controls.Add(this.vSpacing);
            this.expanderPanel1.Controls.Add(this.hSpacing);
            this.expanderPanel1.Controls.Add(this.apply);
            this.expanderPanel1.Controls.Add(this.txtHSpacing);
            this.expanderPanel1.Controls.Add(this.chkAutoLayout);
            this.expanderPanel1.Controls.Add(this.txtVSpacing);
            this.expanderPanel1.Controls.Add(this.txtTMarigin);
            this.expanderPanel1.Controls.Add(this.lMarigin);
            this.expanderPanel1.Controls.Add(this.tMarigin);
            this.expanderPanel1.Controls.Add(this.txtLMarigin);
            this.expanderPanel1.Controls.Add(this.lytTypLbl);
            this.expanderPanel1.Controls.Add(this.comboLytType);
            this.expanderPanel1.Dock = System.Windows.Forms.DockStyle.Top;
            this.expanderPanel1.Location = new System.Drawing.Point(0, 0);
            this.expanderPanel1.Name = "expanderPanel1";
            this.expanderPanel1.Padding = new System.Windows.Forms.Padding(10, 10, 10, 10);
            this.expanderPanel1.Size = new System.Drawing.Size(279, 344);
            this.expanderPanel1.TabIndex = 0;
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.label1.Location = new System.Drawing.Point(13, 253);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(72, 15);
            this.label1.TabIndex = 45;
            this.label1.Text = "Auto Layout";
            // 
            // vSpacing
            // 
            this.vSpacing.AutoSize = true;
            this.vSpacing.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.vSpacing.Location = new System.Drawing.Point(13, 133);
            this.vSpacing.Name = "vSpacing";
            this.vSpacing.Size = new System.Drawing.Size(91, 15);
            this.vSpacing.TabIndex = 37;
            this.vSpacing.Text = "Vertical Spacing";
            // 
            // hSpacing
            // 
            this.hSpacing.AutoSize = true;
            this.hSpacing.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.hSpacing.Location = new System.Drawing.Point(13, 93);
            this.hSpacing.Name = "hSpacing";
            this.hSpacing.Size = new System.Drawing.Size(107, 15);
            this.hSpacing.TabIndex = 36;
            this.hSpacing.Text = "Horizontal Spacing";
            // 
            // apply
            // 
            this.apply.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(163)))), ((int)(((byte)(0)))));
            this.apply.FlatAppearance.BorderSize = 0;
            this.apply.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
            this.apply.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.apply.ForeColor = System.Drawing.Color.White;
            this.apply.Location = new System.Drawing.Point(109, 293);
            this.apply.Name = "apply";
            this.apply.Size = new System.Drawing.Size(80, 30);
            this.apply.TabIndex = 46;
            this.apply.Text = "Apply";
            this.apply.UseVisualStyleBackColor = false;
            // 
            // txtHSpacing
            // 
            this.txtHSpacing.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.txtHSpacing.Location = new System.Drawing.Point(144, 91);
            this.txtHSpacing.MaxLength = 3;
            this.txtHSpacing.Name = "txtHSpacing";
            this.txtHSpacing.Size = new System.Drawing.Size(110, 23);
            this.txtHSpacing.TabIndex = 38;
            // 
            // chkAutoLayout
            // 
            this.chkAutoLayout.AutoSize = true;
            this.chkAutoLayout.FlatAppearance.BorderSize = 0;
            this.chkAutoLayout.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
            this.chkAutoLayout.Font = new System.Drawing.Font("Arial", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.chkAutoLayout.Location = new System.Drawing.Point(144, 255);
            this.chkAutoLayout.Name = "chkAutoLayout";
            this.chkAutoLayout.Size = new System.Drawing.Size(12, 11);
            this.chkAutoLayout.TabIndex = 44;
            this.chkAutoLayout.UseVisualStyleBackColor = true;
            // 
            // txtVSpacing
            // 
            this.txtVSpacing.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.txtVSpacing.Location = new System.Drawing.Point(144, 131);
            this.txtVSpacing.MaxLength = 3;
            this.txtVSpacing.Name = "txtVSpacing";
            this.txtVSpacing.Size = new System.Drawing.Size(110, 23);
            this.txtVSpacing.TabIndex = 39;
            // 
            // txtTMarigin
            // 
            this.txtTMarigin.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.txtTMarigin.Location = new System.Drawing.Point(144, 211);
            this.txtTMarigin.MaxLength = 3;
            this.txtTMarigin.Name = "txtTMarigin";
            this.txtTMarigin.Size = new System.Drawing.Size(110, 23);
            this.txtTMarigin.TabIndex = 43;
            // 
            // lMarigin
            // 
            this.lMarigin.AutoSize = true;
            this.lMarigin.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.lMarigin.Location = new System.Drawing.Point(13, 173);
            this.lMarigin.Name = "lMarigin";
            this.lMarigin.Size = new System.Drawing.Size(71, 15);
            this.lMarigin.TabIndex = 40;
            this.lMarigin.Text = "Left Marigin";
            // 
            // tMarigin
            // 
            this.tMarigin.AutoSize = true;
            this.tMarigin.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.tMarigin.Location = new System.Drawing.Point(13, 213);
            this.tMarigin.Name = "tMarigin";
            this.tMarigin.Size = new System.Drawing.Size(72, 15);
            this.tMarigin.TabIndex = 41;
            this.tMarigin.Text = "Top Marigin";
            // 
            // txtLMarigin
            // 
            this.txtLMarigin.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.txtLMarigin.Location = new System.Drawing.Point(144, 171);
            this.txtLMarigin.MaxLength = 3;
            this.txtLMarigin.Name = "txtLMarigin";
            this.txtLMarigin.Size = new System.Drawing.Size(110, 23);
            this.txtLMarigin.TabIndex = 42;
            // 
            // lytTypLbl
            // 
            this.lytTypLbl.AutoSize = true;
            this.lytTypLbl.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.lytTypLbl.Location = new System.Drawing.Point(13, 53);
            this.lytTypLbl.Name = "lytTypLbl";
            this.lytTypLbl.Size = new System.Drawing.Size(72, 15);
            this.lytTypLbl.TabIndex = 35;
            this.lytTypLbl.Text = "Layout Type";
            // 
            // comboLytType
            // 
            this.comboLytType.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
            this.comboLytType.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.comboLytType.FormattingEnabled = true;
            this.comboLytType.Items.AddRange(new object[] {
            "WaterFall",
            "Horizontal"});
            this.comboLytType.Location = new System.Drawing.Point(144, 51);
            this.comboLytType.Name = "comboLytType";
            this.comboLytType.Size = new System.Drawing.Size(110, 23);
            this.comboLytType.TabIndex = 34;
            // 
            // diagram1
            // 
            this.diagram1.Controller.PasteOffset = new System.Drawing.SizeF(10F, 10F);
            this.diagram1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.diagram1.HScroll = true;
            this.diagram1.LayoutManager = null;
            this.diagram1.Location = new System.Drawing.Point(2, 2);
            this.diagram1.MetroScrollBars = true;
            this.diagram1.Model = this.model1;
            this.diagram1.Name = "diagram1";
            this.diagram1.ScrollVirtualBounds = new System.Drawing.RectangleF(0, 0, 0, 0);
            this.diagram1.Size = new System.Drawing.Size(749, 607);
            this.diagram1.SmartSizeBox = false;
            this.diagram1.TabIndex = 2;
            this.diagram1.Text = "diagram1";
            this.diagram1.Model.LineBridgingEnabled = true;
            // 
            // 
            // 
            this.diagram1.View.ClientRectangle = new System.Drawing.Rectangle(0, 0, 0, 0);
            this.diagram1.View.Controller = this.diagram1.Controller;
            this.diagram1.View.Grid.MinPixelSpacing = 4F;
            this.diagram1.View.Grid.Visible = false;
            this.diagram1.View.ScrollVirtualBounds = new System.Drawing.RectangleF(0, 0, 0, 0);
            this.diagram1.View.ZoomType = Syncfusion.Windows.Forms.Diagram.ZoomType.Center;
            this.diagram1.VScroll = true;
            // 
            // model1
            // 
            this.model1.BackgroundStyle.PathBrushStyle = Syncfusion.Windows.Forms.Diagram.PathGradientBrushStyle.RectangleCenter;
            this.model1.DocumentScale.DisplayName = "No Scale";
            this.model1.DocumentScale.Height = 1F;
            this.model1.DocumentScale.Width = 1F;
            this.model1.DocumentSize.Height = 1169F;
            this.model1.DocumentSize.Width = 1227F;
            this.model1.LineStyle.DashPattern = null;
            this.model1.LineStyle.LineColor = System.Drawing.Color.Black;
            this.model1.LineStyle.LineWidth = 0F;
            this.model1.LogicalSize = new System.Drawing.SizeF(1227F, 1169F);
            this.model1.ShadowStyle.Color = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(105)))), ((int)(((byte)(105)))), ((int)(((byte)(105)))));
            this.model1.ShadowStyle.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(105)))), ((int)(((byte)(105)))), ((int)(((byte)(105)))));
            // 
            // lytProp
            // 
            this.lytProp.AutoEllipsis = true;
            this.lytProp.BackColor = System.Drawing.Color.White;
            this.lytProp.Font = new System.Drawing.Font("Arial", 11F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.lytProp.Location = new System.Drawing.Point(13, 20);
            this.lytProp.Name = "lytProp";
            this.lytProp.Size = new System.Drawing.Size(99, 20);
            this.lytProp.TabIndex = 47;
            this.lytProp.Text = "Properties";
            // 
            // label2
            // 
            this.label2.AutoEllipsis = true;
            this.label2.BackColor = System.Drawing.Color.White;
            this.label2.Font = new System.Drawing.Font("Arial", 11F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.label2.Location = new System.Drawing.Point(13, 19);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(99, 20);
            this.label2.TabIndex = 39;
            this.label2.Text = "Expander";
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(1032, 611);
            this.Controls.Add(this.diagram1);
            this.Controls.Add(this.panel2);
            this.Name = "Form1";
            this.Padding = new System.Windows.Forms.Padding(2, 2, 2, 2);
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "OrgChartLayout";
            this.Load += new System.EventHandler(this.Form1_Load);
            this.panel2.ResumeLayout(false);
            this.expanderPanel2.ResumeLayout(false);
            this.expanderPanel2.PerformLayout();
            this.expanderPanel1.ResumeLayout(false);
            this.expanderPanel1.PerformLayout();
            ((System.ComponentModel.ISupportInitialize)(this.diagram1)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.model1)).EndInit();
            this.ResumeLayout(false);

        }

        #endregion

       
        private System.Windows.Forms.Panel panel2;
        private System.Windows.Forms.Panel expanderPanel2;
        private System.Windows.Forms.Label expSymShapeLbl;
        private System.Windows.Forms.ComboBox comboBShape;
        private System.Windows.Forms.Label bShape;
        private System.Windows.Forms.ComboBox comboExpSymbol;
        private System.Windows.Forms.Panel expanderPanel1;
        private Syncfusion.Windows.Forms.Diagram.Controls.Diagram diagram1;
        private Syncfusion.Windows.Forms.Diagram.Model model1;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.Label vSpacing;
        private System.Windows.Forms.Label hSpacing;
        private System.Windows.Forms.Button apply;
        private System.Windows.Forms.TextBox txtHSpacing;
        private System.Windows.Forms.CheckBox chkAutoLayout;
        private System.Windows.Forms.TextBox txtVSpacing;
        private System.Windows.Forms.TextBox txtTMarigin;
        private System.Windows.Forms.Label lMarigin;
        private System.Windows.Forms.Label tMarigin;
        private System.Windows.Forms.TextBox txtLMarigin;
        private System.Windows.Forms.Label lytTypLbl;
        private System.Windows.Forms.ComboBox comboLytType;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.Label lytProp;

    }
}

```

### src/components/diagram-org-chart-layout/diagram.cs

```cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Syncfusion.Windows.Forms.Diagram;
using System.Drawing.Imaging;
using Syncfusion.Windows.Forms.Tools;
using Syncfusion.Windows.Forms.Diagram.Controls;
using System.Drawing.Drawing2D;
using Syncfusion.Windows.Forms;
using System.IO;
using System.Drawing.Printing;
using Syncfusion.SVG.IO;
using System.Collections;
using System.Xml;

namespace OrgChartLayout
{
    public partial class Form1 : MetroForm
    {
        #region Members
        protected OrgChartLayoutManager dtLayoutMgr;
        #endregion

        #region Form Initialize
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {            
            diagram1.BeginUpdate();
            this.diagram1.Controller.InPlaceEditing = false;
            this.dtLayoutMgr = new OrgChartLayoutManager(this.diagram1.Model, RotateDirection.TopToBottom, 40, 50, LayoutType.Waterfall, 1);
            dtLayoutMgr.LeftMargin = 10;
            dtLayoutMgr.TopMargin = 10;
            dtLayoutMgr.VerticalSpacing = 50;
            diagram1.LayoutManager = dtLayoutMgr;
            DiagramAppearance();
            InitializeDiagramFromXMLData();
            this.diagram1.View.SelectionList.Clear();

            txtHSpacing.Text = dtLayoutMgr.HorizontalSpacing.ToString();
            txtVSpacing.Text = dtLayoutMgr.VerticalSpacing.ToString();
            txtLMarigin.Text = dtLayoutMgr.LeftMargin.ToString();
            txtTMarigin.Text = dtLayoutMgr.TopMargin.ToString();
            chkAutoLayout.Checked = dtLayoutMgr.AutoLayout;

            comboLytType.SelectedIndex = 0;
            comboBShape.SelectedIndex = 1;
            comboExpSymbol.SelectedIndex = 0;

            diagram1.EndUpdate();
            comboBShape.SelectedIndexChanged += new EventHandler(comboBShape_SelectedIndexChanged);
            comboExpSymbol.SelectedIndexChanged += new EventHandler(comboExpSymbol_SelectedIndexChanged);
            apply.Click += new EventHandler(apply_Click);
            diagram1.MouseMove += new MouseEventHandler(diagram1_MouseMove);
            diagram1.EventSink.NodeMouseEnter += new Syncfusion.Windows.Forms.Diagram.NodeMouseEventHandler(EventSink_NodeMouseEnter);
            this.dtLayoutMgr.UpdateLayout(this);
        }
        #endregion

        #region Private Methods
        /// <summary>
        /// Change's the appearance of Diagram
        /// </summary>
        private void DiagramAppearance()
        {
            //this.diagram1.MetroScrollBars = true;            
            this.diagram1.View.HandleRenderer.HandleColor = Color.AliceBlue;
            this.diagram1.View.HandleRenderer.HandleOutlineColor = Color.SkyBlue;
            this.diagram1.Model.RenderingStyle.SmoothingMode = SmoothingMode.HighQuality;
            this.diagram1.View.BackgroundColor = Color.White;            
            this.diagram1.Model.SizeToContent = true;

        }
        #endregion

        #region Initialize Diagram

        /// <summary>
        /// Initialize the diagram from XML file.
        /// </summary>
        protected void InitializeDiagramFromXMLData()
        {
#if !NETCORE
            string datasrcpath = @"..\..\..\..\..\..\common\Data\Diagram\xml\OrgLayout.xml";
#else
            string datasrcpath = OrgChartLayoutDataSource.GetXmlPath() ?? string.Empty;
            if (string.IsNullOrEmpty(datasrcpath)) return;
#endif

            // Read data from the XML data file and populate a Hashtable using the employee ID as the key
            Hashtable lstEmployees = this.ReadEmployeeDataFromXMLFile(datasrcpath);

            // Create a manager-employee nested list with top-level employees forming the root nodes
            ArrayList sortedlist = this.GetSortedEmployeesList(lstEmployees);

            foreach (Employee emply in sortedlist)
            {
                this.IterUpdateSubEmployeeCount(emply);
            }

            // Create diagram symbol nodes for each employee and initialize the diagram
            this.CreateOrgDiagramFromList(sortedlist);
            lstEmployees.Clear();
            sortedlist.Clear();
        }

        /// <summary>
        /// Read the data from the XML file
        /// </summary>
        /// <param name="datasrc">Path of the XML File</param>
        /// <returns>returns the employee table</returns>
        protected Hashtable ReadEmployeeDataFromXMLFile(string datasrc)
        {
            Hashtable lstEmployee = new Hashtable();  

            // Use the XML DOM to read data from the employees XML data file
            XmlDocument xmldoc = new XmlDocument();
#if SyncfusionFramework4_0
            xmldoc.XmlResolver = null;
#endif
            xmldoc.Load(datasrc);
            if (xmldoc.DocumentElement.HasChildNodes)
            {
                XmlNodeList employeelist = xmldoc.DocumentElement.ChildNodes;
                for (int i = 0; i < employeelist.Count; i++)
                {
                    // Create an Employee instance to represent each employee
                    Employee emply = new Employee();

                    XmlNode employeenode = employeelist[i];
                    XmlNodeList employeedatalist = employeenode.ChildNodes;
                    IEnumerator employeedata = employeedatalist.GetEnumerator();
                    employeedata.Reset();
                    while (employeedata.MoveNext())
                    {
                        XmlNode dataelement = employeedata.Current as XmlNode;
                        switch (dataelement.Name)
                        {
                            case "Name":
                                emply.EmployeeName = "Name :" + dataelement.InnerText;
                                break;
                            case "EmployeeID":
                                emply.EmployeeID = dataelement.InnerText;
                                emply.EmployeeName += System.Environment.NewLine + "Emp ID :" + dataelement.InnerText;
                                break;
                            case "Designation":
                                emply.Designation = dataelement.InnerText;
                                emply.EmployeeName += System.Environment.NewLine + "Des :" + dataelement.InnerText;
                                break;
                            case "DOJ":
                                emply.DOJ = dataelement.InnerText;
                                emply.EmployeeName += System.Environment.NewLine + "DOJ :" + dataelement.InnerText;
                                break;
                            case "ImageNo":
                                emply.ImageName = dataelement.InnerText;
                                break;
                            case "ManagerID":
                                emply.ManagerID = dataelement.InnerText;
                                break;
                        }
                    }
                    lstEmployee.Add(emply.EmployeeID,emply);
                }
            }

            return lstEmployee;
        }

        /// <summary>
        ///  Rearrange the employees collection as a manager-subemployee nested tree
        /// </summary>
        /// <param name="htemployees">Employee table</param>
        /// <returns>returns the sorted list</returns>
        protected ArrayList GetSortedEmployeesList(Hashtable htemployees)
        {           
            ICollection employees = htemployees.Values;
            ArrayList sortedlist = new ArrayList();
            foreach (Employee emply in employees)
            {
                if (emply.ManagerID == string.Empty)
                {
                    // Employees without a ManagerID are top-level nodes in the org tree
                    sortedlist.Add(emply);
                }
                else
                {
                    // Find the employee instance associated with the managerID and add this object as 
                    // a subemployee of the manager node.
                    Employee manager = (Employee)htemployees[emply.ManagerID];
                    if (manager != null)
                        manager.SubEmployees.Add(emply);
                }
            }

            return sortedlist;            
        }

        /// <summary>
        /// generates the sub employees count
        /// </summary>
        /// <param name="empl">Employee business object</param>
        protected void IterUpdateSubEmployeeCount(Employee empl)
        {
            empl.RecSubEmployeeCount = empl.SubEmployees.Count;
            foreach (Employee subempl in empl.SubEmployees)
            {
                this.IterUpdateSubEmployeeCount(subempl);
                empl.RecSubEmployeeCount += subempl.RecSubEmployeeCount;
            }
        }       
        
        /// <summary>
        /// Create diagram symbol nodes for each employee in the organization and add these symbols to the diagram
        /// Create links between manager and sub-employees to depict the org structure
        /// </summary>
        /// <param name="alemployees"> Employees list</param>
        protected void CreateOrgDiagramFromList(ArrayList alemployees)
        {
            // Temporarily suspend the Diagram Model redrawing
            this.diagram1.Model.BeginUpdate();

            foreach (Employee emply in alemployees)
            {
                string fileName = OrgChartLayoutDataSource.GetEmployeeImagePath(emply.ImageName);
                EmpSymbol emplysymbol = new EmpSymbol(fileName);
                emplysymbol.LineStyle.LineColor = Color.LightSkyBlue;
                emplysymbol.EmployeeName = emply.EmployeeName;
                this.diagram1.Model.AppendChild(emplysymbol);
                this.IterCreateEmployeeSymbol(emply, emplysymbol);
            }

            // ReEnable the Model redraw
            this.diagram1.Model.EndUpdate();

            // Instruct the LayoutManager to calculate and layout the diagram nodes
            LayoutNodes();
        }

        /// <summary>
        ///  Iterative sub-employee symbol node creation
        /// </summary>
        /// <param name="emply">Employess business object</param>
        /// <param name="emplysymbol">Employee Node</param>
        protected void IterCreateEmployeeSymbol(Employee emply, EmpSymbol emplysymbol)
        {
            foreach (Employee subemply in emply.SubEmployees)
            {
                string fileName = OrgChartLayoutDataSource.GetEmployeeImagePath(subemply.ImageName);
                // Create a EmployeeSymbol for each of the sub-employees of the particular employee //Waterfall, Horizontal
                EmpSymbol subemplysymbol = new EmpSymbol(fileName);
                subemplysymbol.LineStyle.LineColor = Color.LightSkyBlue;
                subemplysymbol.EmployeeName = emply.EmployeeName;
                this.diagram1.Model.AppendChild(subemplysymbol);

                emplysymbol.EnableCentralPort = true;
                subemplysymbol.EnableCentralPort = true;
                ConnectNodes(emplysymbol, subemplysymbol);

                this.IterCreateEmployeeSymbol(subemply, subemplysymbol);
            }

        }

        /// <summary>
        /// Connects the nodes
        /// </summary>
        /// <param name="emplysymbol">Parent Node</param>
        /// <param name="subemplysymbol">Child node</param>
        private void ConnectNodes(Node emplysymbol, Node subemplysymbol)
        {
            OrgLineConnector ortholink = new OrgLineConnector(PointF.Empty, new PointF(0, 1));            
            ortholink.LineStyle.LineWidth = 1f;
            ortholink.LineStyle.LineColor = Color.Black;
            ortholink.HeadDecorator.DecoratorShape = DecoratorShape.Filled45Arrow;            
            ortholink.HeadDecorator.FillStyle.Color = Color.Black;
            this.diagram1.Model.AppendChild(ortholink);

            if (emplysymbol.CentralPort != null && subemplysymbol.CentralPort != null)
            {
                emplysymbol.CentralPort.TryConnect(ortholink.TailEndPoint);
                subemplysymbol.CentralPort.TryConnect(ortholink.HeadEndPoint);
            }

            this.diagram1.Controller.SendToBack();
        }

#endregion
        
#region Event Handlers
        
        private void dialog_BeginLayout(OrgChartLayoutManager layout)
        {
            this.diagram1.LayoutManager = layout;
            LayoutNodes();
        }

        void apply_Click(object sender, EventArgs e)
        {
            this.diagram1.BeginUpdate();
            dtLayoutMgr = new OrgChartLayoutManager(this.diagram1.Model, RotateDirection.TopToBottom, 20, 50, (LayoutType)Enum.Parse(typeof(LayoutType), this.comboLytType.SelectedItem.ToString(), true), 1, true);
            if (txtHSpacing.Text != string.Empty)
                dtLayoutMgr.LeftMargin = float.Parse(txtLMarigin.Text);
            if (txtVSpacing.Text != string.Empty)
                dtLayoutMgr.TopMargin = float.Parse(txtTMarigin.Text);
            if (txtLMarigin.Text != string.Empty)
                dtLayoutMgr.HorizontalSpacing = float.Parse(txtHSpacing.Text);
            if (txtTMarigin.Text != string.Empty)
                dtLayoutMgr.VerticalSpacing = float.Parse(txtVSpacing.Text);

            dtLayoutMgr.AutoLayout = chkAutoLayout.Checked;

            this.diagram1.LayoutManager = this.dtLayoutMgr;
            this.dtLayoutMgr.UpdateLayout(null);
            this.diagram1.EndUpdate();
            this.diagram1.UpdateView();
        }

        void comboExpSymbol_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.diagram1.BeginUpdate();
            foreach (Node node in diagram1.Model.Nodes)
            {
                if (node is EmpSymbol)
                {
                    if (comboExpSymbol.SelectedIndex == 1)
                    {
                        ((EmpSymbol)node).SymbolShapeType = EmpSymbol.SymbolShape.PlusMinus;
                    }
                    else if (comboExpSymbol.SelectedIndex == 0)
                    {
                        ((EmpSymbol)node).SymbolShapeType = EmpSymbol.SymbolShape.RightDownTriangle;
                    }
                }
            }
            this.diagram1.Refresh();
            this.diagram1.EndUpdate();
        }

        void comboBShape_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.diagram1.BeginUpdate();
            foreach (Node node in diagram1.Model.Nodes)
            {
                if (node is EmpSymbol)
                {
                    if (comboBShape.SelectedIndex == 1)
                    {
                        ((EmpSymbol)node).BackgroundShapeType = EmpSymbol.BackgroundShape.ellipse;
                    }
                    else if (comboBShape.SelectedIndex == 0)
                    {
                        ((EmpSymbol)node).BackgroundShapeType = EmpSymbol.BackgroundShape.Rectangle;
                    }
                }
            }
            this.diagram1.Refresh();
            this.diagram1.EndUpdate();
        }

        void EventSink_NodeMouseEnter(Syncfusion.Windows.Forms.Diagram.NodeMouseEventArgs evtArgs)
        {
            diagram1.Controller.ActiveTool.ActionCursor = Cursors.Arrow;
        }

        void diagram1_MouseMove(object sender, MouseEventArgs e)
        {
            EmpSymbol node = diagram1.Controller.GetNodeAtPoint(diagram1.Controller.ConvertToModelCoordinates(e.Location)) as EmpSymbol;
            if (node != null)
            {
                node.MouseMove(diagram1.Controller.ConvertToModelCoordinates(e.Location));
            }
        }
#endregion

#region Helper Methods

        private void LayoutNodes()
        {
            // Temporarily suspend the layoutmanager
            this.diagram1.LayoutManager.AutoLayout = false;

            this.diagram1.LayoutManager.Nodes.Clear();
            this.diagram1.LayoutManager.Nodes.AddRange(this.diagram1.Model.Nodes);
            this.diagram1.LayoutManager.UpdateLayout(null);
        }        
#endregion
    }
}

```
