■ DiagramControl 클래스의 CustomDrawItem 이벤트를 사용해 항목을 커스텀 그리는 방법을 보여준다.
▶ 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 |
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 } } |