첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
------------------------------------------------------------------------------------------------------------------------------------------------------
728x90
728x170

TestProject.zip
0.01MB

▶ MainForm.cs

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
    }
}
728x90
그리드형(광고전용)
Posted by icodebroker
,