■ DrawLine 클래스의 Select/DraggedLine 이벤트를 사용해 라인을 드래그하는 방법을 보여준다.
▶ 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 |
using System.Drawing; using System.Windows.Forms; using Steema.TeeChart.Drawing; using Steema.TeeChart.Styles; using Steema.TeeChart.Tools; namespace TestProject { /// <summary> /// 메인 폼 /// </summary> public partial class MainForm : Form { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 라인 /// </summary> private Line line; /// <summary> /// 라인 그리기 /// </summary> private DrawLine drawLine; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainForm() /// <summary> /// 생성자 /// </summary> public MainForm() { InitializeComponent(); Text = "DrawLine 클래스 : Select/DraggedLine 이벤트를 사용해 라인 드래그하기"; this.tChart.Panel.Pen = new ChartPen(Color.Black); this.line = new Line(this.tChart.Chart); this.line.FillSampleValues(30); this.drawLine = new DrawLine(this.tChart.Chart); this.drawLine.Pen.Width = 2; this.drawLine.Pen.Color = Color.Blue; this.drawLine.Active = true; this.drawLine.EnableDraw = true; this.drawLine.EnableSelect = true; this.drawLine.Button = MouseButtons.Left; DrawLineItem item = new DrawLineItem(this.drawLine); double delta = line.YValues.Range / 5.0; item.StartPos = new PointDouble(5 , this.line.YValues.Maximum - delta); item.EndPos = new PointDouble(15, this.line.YValues.Minimum + delta); this.drawLine.Select += drawLine_Select; this.drawLine.DraggedLine += drawLine_DraggedLine; this.drawLine.NewLine += drawLine_NewLine; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private //////////////////////////////////////////////////////////////////////////////// Event #region 라인 그리기 선택시 처리하기 - drawLine_Select(sender) /// <summary> /// 라인 그리기 선택시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> private void drawLine_Select(DrawLine sender) { SetLinePositionValueLebelData(); } #endregion #region 라인 그리기 라인 드래그시 처리하기 - drawLine_DraggedLine(sender) /// <summary> /// 라인 그리기 라인 드래그시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> private void drawLine_DraggedLine(DrawLine sender) { SetLinePositionValueLebelData(); } #endregion #region 라인 그리기 신규 라인 생성시 처리하기 - drawLine_NewLine(sender) /// <summary> /// 라인 그리기 신규 라인 생성시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> private void drawLine_NewLine(DrawLine sender) { SetLinePositionValueLebelData(); } #endregion //////////////////////////////////////////////////////////////////////////////// Function #region 라인 위치 값 레이블 데이터 설정하기 - SetLinePositionValueLebelData() /// <summary> /// 라인 위치 값 레이블 데이터 설정하기 /// </summary> private void SetLinePositionValueLebelData() { DrawLineItem item = this.drawLine.Selected; this.linePositionValueLabel.Text = $"({item.StartPos.X:0.00}, {item.StartPos.Y:0.00}) - ({item.EndPos.X:0.00}, {item.EndPos.Y:0.00})"; } #endregion } } |