■ CursorTool 클래스를 사용하는 방법을 보여준다.
▶ 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 206 207 208 209 210 211 212 213 214 |
using System; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; using Steema.TeeChart; using Steema.TeeChart.Drawing; using Steema.TeeChart.Editors.Tools; using Steema.TeeChart.Styles; using Steema.TeeChart.Tools; namespace TestProject { /// <summary> /// 메인 폼 /// </summary> public partial class MainForm : Form { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 라인 1 /// </summary> private Line line1; /// <summary> /// 라인 2 /// </summary> private Line line2; /// <summary> /// 라인 2 수직 축 /// </summary> private Axis line2VertAxis; /// <summary> /// 커서 도구 1 /// </summary> private CursorTool cursorTool1; /// <summary> /// 커서 도구 2 /// </summary> private CursorTool cursorTool2; /// <summary> /// 플래그 /// </summary> private bool flag; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainForm() /// <summary> /// 생성자 /// </summary> public MainForm() { InitializeComponent(); Text = "CursorTool 클래스 사용하기"; this.activeCheckBox.Checked = true; this.tChart.Panel.Pen = new ChartPen(Color.Black); this.tChart.Axes.Left.StartPosition = 0; this.tChart.Axes.Left.EndPosition = 50; this.tChart.Axes.Left.AutomaticMinimum = false; this.tChart.Axes.Left.Minimum = 0.0; this.line2VertAxis = new Axis(); this.line2VertAxis.Horizontal = false; this.line2VertAxis.StartPosition = 50; this.tChart.Axes.Custom.Add(this.line2VertAxis); this.line1 = new Line(this.tChart.Chart); this.line1.FillSampleValues(100); this.line2 = new Line(this.tChart.Chart); this.line2.CustomVertAxis = this.line2VertAxis; this.line2.FillSampleValues(100); this.cursorTool1 = new CursorTool(this.tChart.Chart); this.cursorTool1.Series = this.line1; this.cursorTool1.Style = CursorToolStyles.Vertical; this.cursorTool1.Pen.Width = 2; this.cursorTool1.Pen.Style = DashStyle.Dash; this.cursorTool1.Pen.Color = Color.Navy; this.cursorTool1.FollowMouse = false; this.cursorTool1.Snap = false; this.cursorTool2 = new CursorTool(this.tChart.Chart); this.cursorTool2.Series = this.line2; this.cursorTool2.Style = CursorToolStyles.Both; this.cursorTool2.Pen.Width = 2; this.cursorTool2.Pen.Style = DashStyle.Dot; this.cursorTool2.Pen.Color = Color.Plum; this.cursorTool2.FollowMouse = true; this.snapCheckBox.CheckedChanged += snapCheckBox_CheckedChanged; this.activeCheckBox.CheckedChanged += activeCheckBox_CheckedChanged; this.editButton.Click += editButton_Click; this.tChart.BeforeDrawSeries += tChart_BeforeDrawSeries; this.cursorTool1.Change += cursorTool1_Change; this.cursorTool2.Change += cursorTool2_Change; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private //////////////////////////////////////////////////////////////////////////////// Event #region 스냅 체크 박스 체크 변경시 처리하기 - snapCheckBox_CheckedChanged(sender, e) /// <summary> /// 스냅 체크 박스 체크 변경시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void snapCheckBox_CheckedChanged(object sender, EventArgs e) { this.cursorTool1.Snap = this.snapCheckBox.Checked; } #endregion #region 활성화 체크 박스 체크 변경시 처리하기 - activeCheckBox_CheckedChanged(sender, e) /// <summary> /// 활성화 체크 박스 체크 변경시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void activeCheckBox_CheckedChanged(object sender, EventArgs e) { this.cursorTool1.Active = this.activeCheckBox.Checked; } #endregion #region 편집 버튼 클릭시 처리하기 - editButton_Click(sender, e) /// <summary> /// 편집 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void editButton_Click(object sender, EventArgs e) { ToolsEditor.ShowEditor(this.cursorTool1); } #endregion #region TChart 시리즈 그리기 전 처리하기 - tChart_BeforeDrawSeries(sender, graphics3D) /// <summary> /// TChart 시리즈 그리기 전 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="graphics3D">이벤트 인자</param> private void tChart_BeforeDrawSeries(object sender, Graphics3D graphics3D) { if(this.flag) { this.cursorTool1.XValue = 0.5 * (this.line1.XValues.Minimum + this.line1.XValues.Maximum); this.flag = false; } } #endregion #region 커서 도구 1 변경시 처리하기 - cursorTool1_Change(sender, e) /// <summary> /// 커서 도구 1 변경시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void cursorTool1_Change(object sender, CursorChangeEventArgs e) { this.messageLabel1.Text = $"X={e.XValue:#.00}"; } #endregion #region 커서 도구 2 변경시 처리하기 - cursorTool2_Change(sender, e) /// <summary> /// 커서 도구 2 변경시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void cursorTool2_Change(object sender, CursorChangeEventArgs e) { this.messageLabel2.Text = $"X={e.XValue:#.00}; Y={e.YValue:#.00}"; } #endregion } } |