using System.Drawing;
using DevExpress.Diagram.Core;
using DevExpress.Utils;
using DevExpress.XtraDiagram;
using DevExpress.XtraEditors;
namespace TestProject
{
/// <summary>
/// 메인 폼
/// </summary>
public partial class MainForm : XtraForm
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Field
////////////////////////////////////////////////////////////////////////////////////////// Private
#region Field
/// <summary>
/// 포인트 크기
/// </summary>
private int pointSize = 8;
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainForm()
/// <summary>
/// 생성자
/// </summary>
public MainForm()
{
InitializeComponent();
this.diagramControl.OptionsView.ShowGrid = false;
this.diagramControl.OptionsView.ShowRulers = false;
this.diagramControl.OptionsView.ShowPageBreaks = false;
DiagramShape shape1 = new DiagramShape();
shape1.Size = new SizeF(100f, 100f);
shape1.Position = new PointFloat(450f, 200f);
shape1.Shape = BasicShapes.Ellipse;
shape1.Appearance.BorderSize = 4;
shape1.Appearance.BorderColor = Color.FromArgb(128, 0, 0, 0);
shape1.Appearance.BackColor = Color.White;
shape1.Appearance.Font = new Font("나눔고딕코딩", 12f, FontStyle.Bold);
shape1.Appearance.ForeColor = Color.FromArgb(128, 0, 0, 0);
shape1.Content = "도형1";
this.diagramControl.Items.Add(shape1);
DiagramShape shape2 = new DiagramShape();
shape2.Size = new SizeF(100F, 100F);
shape2.Position = new PointFloat(300f, 400f);
shape2.Shape = BasicShapes.Ellipse;
shape2.Appearance.BorderSize = 4;
shape2.Appearance.BorderColor = Color.FromArgb(128, 0, 0, 0);
shape2.Appearance.BackColor = Color.White;
shape2.Appearance.Font = new Font("나눔고딕코딩", 12f, FontStyle.Bold);
shape2.Appearance.ForeColor = Color.FromArgb(128, 0, 0, 0);
shape2.Content = "도형2";
this.diagramControl.Items.Add(shape2);
DiagramConnector connector1 = new DiagramConnector();
connector1.BeginItem = shape1;
connector1.EndItem = shape2;
connector1.Type = ConnectorType.Straight;
connector1.Appearance.BorderSize = 4;
connector1.Appearance.BorderColor = Color.FromArgb(128, 0, 0, 0);
connector1.Appearance.ContentBackground = Color.Transparent;
connector1.Appearance.Font = new Font("나눔고딕코딩", 12f, FontStyle.Bold);
connector1.Appearance.ForeColor = Color.FromArgb(128, 255, 0, 0);
connector1.Content = "연결 1";
this.diagramControl.Items.Add(connector1);
DiagramShape shape3 = new DiagramShape();
shape3.Size = new SizeF(100f, 100f);
shape3.Position = new PointFloat(600f, 400f);
shape3.Shape = BasicShapes.Ellipse;
shape3.Appearance.BorderSize = 4;
shape3.Appearance.BorderColor = Color.FromArgb(128, 0, 0, 0);
shape3.Appearance.BackColor = Color.White;
shape3.Appearance.Font = new Font("나눔고딕코딩", 12f, FontStyle.Bold);
shape3.Appearance.ForeColor = Color.FromArgb(128, 0, 0, 0);
shape3.Content = "도형3";
this.diagramControl.Items.Add(shape3);
DiagramConnector connector2 = new DiagramConnector();
connector2.BeginItem = shape1;
connector2.EndItem = shape3;
connector2.Type = ConnectorType.Straight;
connector2.Appearance.BorderSize = 4;
connector2.Appearance.BorderColor = Color.FromArgb(128, 0, 0, 0);
connector2.Appearance.ContentBackground = Color.Transparent;
connector2.Appearance.Font = new Font("나눔고딕코딩", 12f, FontStyle.Bold);
connector2.Appearance.ForeColor = Color.FromArgb(128, 255, 0, 0);
connector2.Content = "연결 2";
this.diagramControl.Items.Add(connector2);
this.diagramControl.FitToDrawing();
this.diagramControl.CustomDrawItem += diagramControl_CustomDrawItem;
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
#region 다이어그램 항목 커스텀 그리기 - diagramControl_CustomDrawItem(sender, e)
/// <summary>
/// 다이어그램 항목 커스텀 그리기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void diagramControl_CustomDrawItem(object sender, CustomDrawItemEventArgs e)
{
e.DefaultDraw();
DiagramShape shape = e.Item as DiagramShape;
if(shape != null)
{
PointCollection pointCollection = shape.ActualConnectionPoints;
foreach(PointFloat point in pointCollection)
{
e.Graphics.DrawEllipse
(
new Pen(Color.FromArgb(128, Color.Blue), 2),
point.X * shape.Width - pointSize / 2,
point.Y * shape.Height - pointSize / 2,
pointSize,
pointSize
);
}
e.Handled = true;
}
}
#endregion
}
}