■ FastLine 클래스의 Delete 메소드를 사용하는 방법을 보여준다.
▶ 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 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
using System; using System.Drawing; using System.Windows.Forms; using Steema.TeeChart.Drawing; using Steema.TeeChart.Styles; namespace TestProject { /// <summary> /// 메인 폼 /// </summary> public partial class MainForm : Form { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 전체 포인트 수 /// </summary> private int totalPointCount = 10000; /// <summary> /// 스크롤 포인트 수 /// </summary> private int scrollPointCount = 5000; /// <summary> /// 난수기 /// </summary> private Random random = new Random(); /// <summary> /// 고속 라인 1 /// </summary> private FastLine fastLine1; /// <summary> /// 고속 라인 2 /// </summary> private FastLine fastLine2; /// <summary> /// 중단 여부 /// </summary> private bool stopped = true; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainForm() /// <summary> /// 생성자 /// </summary> public MainForm() { InitializeComponent(); Text = "FastLine 클래스 : Delete 메소드 사용하기"; this.tChart.Aspect.View3D = false; this.tChart.Panel.Pen = new ChartPen(Color.Black); this.tChart.Header.Visible = false; this.tChart.Legend.Visible = false; this.tChart.Axes.Left.AxisPen.Width = 1; this.tChart.Axes.Bottom.AxisPen.Width = 1; this.tChart.Axes.Bottom.Labels.RoundFirstLabel = false; this.tChart.Axes.Left.SetMinMax(0, 10000); this.tChart.Axes.Bottom.SetMinMax(1, totalPointCount); this.fastLine1 = new FastLine(this.tChart.Chart); this.fastLine1.AutoRepaint = false; this.fastLine1.DrawAllPoints = false; this.fastLine1.XValues.Order = ValueListOrder.None; this.fastLine2 = new FastLine(this.tChart.Chart); this.fastLine2.AutoRepaint = false; this.fastLine2.DrawAllPoints = false; this.fastLine2.XValues.Order = ValueListOrder.None; FormClosed += Form_FormClosed; this.startButton.Click += startButton_Click; this.drawAllPointsCheckBox.CheckedChanged += drawAllPointsCheckBox_CheckedChanged; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private //////////////////////////////////////////////////////////////////////////////// Event #region 폼을 닫은 경우 처리하기 - Form_FormClosed(sender, e) /// <summary> /// 폼을 닫은 경우 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void Form_FormClosed(object sender, FormClosedEventArgs e) { this.stopped = true; } #endregion #region 시작 버튼 클릭시 처리하기 - startButton_Click(sender, e) /// <summary> /// 시작 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void startButton_Click(object sender, EventArgs e) { if(this.stopped) { this.stopped = false; this.startButton.Text = "중단"; this.totalPointCountTextBox.Enabled = false; this.scrollPointCountTextBox.Enabled = false; this.totalPointCount = Convert.ToInt32(this.totalPointCountTextBox.Text ); this.scrollPointCount = Convert.ToInt32(this.scrollPointCountTextBox.Text); this.tChart.Axes.Bottom.SetMinMax(1,totalPointCount); this.fastLine1.Clear(); this.fastLine2.Clear(); Random random = new Random(); fastLine1.Add(random.Next(10000)); fastLine2.Add(random.Next(5000 )); Application.DoEvents(); while(!this.stopped) { AddPoint(this.fastLine1); AddPoint(this.fastLine2); if(this.fastLine1.Count > this.totalPointCount - 1) { ScrollPoints(); } } } else { this.stopped = true; this.startButton.Text="시작"; this.totalPointCountTextBox.Enabled = true; this.scrollPointCountTextBox.Enabled = true; } } #endregion #region 모든 포인트 그리기 체크 박스 체크 변경시 처리하기 - drawAllPointsCheckBox_CheckedChanged(sender, e) /// <summary> /// 모든 포인트 그리기 체크 박스 체크 변경시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void drawAllPointsCheckBox_CheckedChanged(object sender, EventArgs e) { this.fastLine1.DrawAllPoints = this.drawAllPointsCheckBox.Checked; this.fastLine2.DrawAllPoints = this.drawAllPointsCheckBox.Checked; } #endregion //////////////////////////////////////////////////////////////////////////////// Function #region 포인트 추가하기 - AddPoint(fastLine) /// <summary> /// 포인트 추가하기 /// </summary> /// <param name="fastLine">고속 라인</param> private void AddPoint(FastLine fastLine) { fastLine.Add ( fastLine.XValues.Last + 1, fastLine.YValues.Last + this.random.Next(10) - 4.5 ); } #endregion #region 포인트 스크롤하기 - ScrollPoints() /// <summary> /// 포인트 스크롤하기 /// </summary> private void ScrollPoints() { double lastXValue; double minimumYValue; double maximumYValue; this.fastLine1.Delete(0, this.scrollPointCount); this.fastLine2.Delete(0, this.scrollPointCount); lastXValue = this.fastLine1.XValues.Last; this.tChart.Axes.Bottom.SetMinMax(lastXValue - this.totalPointCount + this.scrollPointCount, lastXValue + this.scrollPointCount); minimumYValue = this.fastLine1.YValues.Minimum; if(this.fastLine2.YValues.Minimum < minimumYValue) { minimumYValue = this.fastLine2.YValues.Minimum; } maximumYValue = this.fastLine1.YValues.Maximum; if(this.fastLine2.YValues.Maximum > maximumYValue) { maximumYValue = this.fastLine2.YValues.Maximum; } this.tChart.Axes.Left.SetMinMax(minimumYValue - minimumYValue * 0.2, maximumYValue + maximumYValue * 0.2); Application.DoEvents(); } #endregion } } |