첨부 소스 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

TestProject.zip
0.01MB

▶ MainForm.cs

using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;

using Steema.TeeChart;
using Steema.TeeChart.Drawing;
using Steema.TeeChart.Styles;

namespace TestProject
{
    /// <summary>
    /// 메인 폼
    /// </summary>
    public partial class MainForm : Form
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Field
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region Field

        /// <summary>
        /// 표면 시리즈
        /// </summary>
        private Surface surface;

        /// <summary>
        /// 타이머
        /// </summary>
        private Timer timer;

        /// <summary>
        /// 델타
        /// </summary>
        private int delta = 1;

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - MainForm()

        /// <summary>
        /// 생성자
        /// </summary>
        public MainForm()
        {
            InitializeComponent();

            Text = "Graphics3D 클래스 : RotationCenter 속성을 사용해 회전 중심 설정하기";

            this.xTrackBar.Minimum       = -100;
            this.xTrackBar.Maximum       = 100;
            this.xTrackBar.TickFrequency = 20;

            this.yTrackBar.Minimum       = -100;
            this.yTrackBar.Maximum       = 100;
            this.yTrackBar.TickFrequency = 20;

            this.zTrackBar.Minimum       = -100;
            this.zTrackBar.Maximum       = 100;
            this.zTrackBar.TickFrequency = 20;

            this.tChart.Aspect.View3D         = true;
            this.tChart.Aspect.Orthogonal     = false;
            this.tChart.Aspect.Chart3DPercent = 100;
            this.tChart.Aspect.Perspective    = 100;
            this.tChart.Panel.Pen             = new ChartPen(Color.Black);

            this.surface = new Surface(this.tChart.Chart);

            this.surface.WireFrame  = true;
            this.surface.StartColor = Color.Red;

            this.surface.FillSampleValues(25);

            this.timer = new Timer();

            this.timer.Interval = 20;

            this.xTrackBar.Scroll               += xTrackBar_Scroll;
            this.yTrackBar.Scroll               += yTrackBar_Scroll;
            this.zTrackBar.Scroll               += zTrackBar_Scroll;
            this.animateCheckBox.CheckedChanged += animateCheckBox_CheckedChanged;
            this.tChart.AfterDraw               += tChart_AfterDraw;
            this.timer.Tick                     += timer_Tick;
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region X 트랙바 스크롤시 처리하기 - xTrackBar_Scroll(sender, e)

        /// <summary>
        /// X 트랙바 스크롤시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void xTrackBar_Scroll(object sender, EventArgs e)
        {
            PointXYZ point = this.tChart.Graphics3D.RotationCenter;

            point.X = (int)this.xTrackBar.Value;

            this.tChart.Graphics3D.RotationCenter = point;

            this.tChart.Invalidate();
        }

        #endregion
        #region Y 트랙바 스크롤시 처리하기 - yTrackBar_Scroll(sender, e)

        /// <summary>
        /// Y 트랙바 스크롤시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void yTrackBar_Scroll(object sender, EventArgs e)
        {
            PointXYZ point = this.tChart.Graphics3D.RotationCenter;

            point.Y = (int)this.yTrackBar.Value;

            this.tChart.Graphics3D.RotationCenter = point;

            this.tChart.Invalidate();
        }

        #endregion
        #region Z 트랙바 스크롤시 처리하기 - zTrackBar_Scroll(sender, e)

        /// <summary>
        /// Z 트랙바 스크롤시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void zTrackBar_Scroll(object sender, EventArgs e)
        {
            PointXYZ point = this.tChart.Graphics3D.RotationCenter;

            point.Z = (int)this.zTrackBar.Value;

            this.tChart.Graphics3D.RotationCenter = point;

            this.tChart.Invalidate();
        }

        #endregion
        #region 애니메이션 체크 박스 체크 변경시 처리하기 - animateCheckBox_CheckedChanged(sender, e)

        /// <summary>
        /// 애니메이션 체크 박스 체크 변경시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void animateCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            this.timer.Enabled = this.animateCheckBox.Checked;
        }

        #endregion
        #region TChart 그리기 후 처리하기 - tChart_AfterDraw(sender, graphics3D)

        /// <summary>
        /// TChart 그리기 후 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="graphics3D">그래픽스 3D</param>
        private void tChart_AfterDraw(object sender, Graphics3D graphics3D)
        {
            TChart tChart = sender as TChart;

            graphics3D.Pen.Style = DashStyle.Dot;
            graphics3D.Pen.Width = 1;
            graphics3D.Pen.Color = Color.Blue;

            int temporaryX = graphics3D.ChartXCenter + graphics3D.RotationCenter.X;
            int temporaryY = graphics3D.ChartYCenter + graphics3D.RotationCenter.Y;
            int temporaryZ = (tChart.Aspect.Width3D / 2) + graphics3D.RotationCenter.Z;

            Rectangle chartRectangle = tChart.Chart.ChartRect;

            graphics3D.HorizontalLine(chartRectangle.Left, chartRectangle.Right, temporaryY, temporaryZ);

            graphics3D.VerticalLine(temporaryX, chartRectangle.Top, chartRectangle.Bottom,temporaryZ);

            graphics3D.ZLine(temporaryX, temporaryY,0, tChart.Aspect.Width3D);
        }

        #endregion
        #region 타이머 틱 처리하기 - timer_Tick(sender, e)

        /// <summary>
        /// 타이머 틱 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void timer_Tick(object sender, EventArgs e)
        {
            this.tChart.Aspect.Rotation += this.delta;

            if(this.tChart.Aspect.Rotation == 360)
            {
                this.delta = -1;
            }
            else if(this.tChart.Aspect.Rotation == 270)
            {
                this.delta = 1;
            }
        }

        #endregion
    }
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요