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

TestProject.zip
0.01MB

▶ MainForm.cs

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

using Steema.TeeChart.Drawing;
using Steema.TeeChart.Tools;

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

        #region Field

        /// <summary>
        /// 사각형 도구
        /// </summary>
        private RectangleTool rectangleTool;

        #endregion

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

        #region 생성자 - MainForm()

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

            Text = "Gradient 클래스 : 커스텀 그라디언트 사용하기";

            this.radialRadioButton.Checked = true;

            this.xOffsetNumericUpDown.Value = 50;
            this.yOffsetNumericUpDown.Value = 50;

            this.tChart.Panel.Pen = new ChartPen(Color.Black);

            this.rectangleTool = new RectangleTool(this.tChart.Chart);

            SetGradient(this.rectangleTool.Shape.Gradient, PathGradientMode.Radial);

            this.tChart.Resize                        += tChart_Resize;
            this.radialRadioButton.CheckedChanged     += radialRadioButton_CheckedChanged;
            this.fromCenterRadioButton.CheckedChanged += fromCenterRadioButton_CheckedChanged;
            this.xOffsetNumericUpDown.ValueChanged    += xOffsetNumericUpDown_ValueChanged;
            this.yOffsetNumericUpDown.ValueChanged    += yOffsetNumericUpDown_ValueChanged;
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Private
        //////////////////////////////////////////////////////////////////////////////// Event

        #region 방사형 라디오 버튼 체크 변경시 처리하기 - radialRadioButton_CheckedChanged(sender, e)

        /// <summary>
        /// 방사형 라디오 버튼 체크 변경시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void radialRadioButton_CheckedChanged(object sender, EventArgs e)
        {
            if(this.radialRadioButton.Checked) 
            {
                this.rectangleTool.Shape.Gradient.Style.Direction = PathGradientMode.Radial;
            }
        }

        #endregion
        #region 중심에서 라디오 버튼 체크 변경시 처리하기 - fromCenterRadioButton_CheckedChanged(sender, e)

        /// <summary>
        /// 중심에서 라디오 버튼 체크 변경시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void fromCenterRadioButton_CheckedChanged(object sender, EventArgs e)
        {
            if(this.fromCenterRadioButton.Checked)
            {
                this.rectangleTool.Shape.Gradient.Style.Direction = PathGradientMode.FromCenter;
            }
        }

        #endregion
        #region X 오프셋 숫자 UP/DOWN 값 변경시 처리하기 - xOffsetNumericUpDown_ValueChanged(sender, e)

        /// <summary>
        /// X 오프셋 숫자 UP/DOWN 값 변경시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void xOffsetNumericUpDown_ValueChanged(object sender, EventArgs e)
        {
            this.rectangleTool.Shape.Gradient.Style.CenterXOffset = (int)this.xOffsetNumericUpDown.Value;
        }

        #endregion
        #region Y 오프셋 숫자 UP/DOWN 값 변경시 처리하기 - yOffsetNumericUpDown_ValueChanged(sender, e)

        /// <summary>
        /// Y 오프셋 숫자 UP/DOWN 값 변경시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void yOffsetNumericUpDown_ValueChanged(object sender, EventArgs e)
        {
            this.rectangleTool.Shape.Gradient.Style.CenterYOffset = (int)this.yOffsetNumericUpDown.Value;
        }

        #endregion
        #region TChart 크기 변경시 처리하기 - tChart_Resize(sender, e)

        /// <summary>
        /// TChart 크기 변경시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void tChart_Resize(object sender, EventArgs e)
        {
            if(this.rectangleTool != null)
            {
                this.radialRadioButton.Checked = true;
            }
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////// Function

        #region 그라디언트 설정하기 - SetGradient(gradient, pathGradientMode)

        /// <summary>
        /// 그라디언트 설정하기
        /// </summary>
        /// <param name="gradient">그라디언트</param>
        /// <param name="pathGradientMode">경로 그라디언트 모드</param>
        private void SetGradient(Gradient gradient, PathGradientMode pathGradientMode)
        {
            Color[] customGradientPaletteColorArray = new Color[]
            {
                Color.FromArgb(120, Color.Red   ),
                Color.FromArgb(120, Color.Yellow),
                Color.FromArgb(120, Color.Blue  ),
                Color.FromArgb(120, Color.Violet)
            };

            gradient.CustomTargetRectangle = new Rectangle(0, 0, this.tChart.Width, this.tChart.Height);
            gradient.ExtendedColorPalette  = customGradientPaletteColorArray;
            gradient.Style.Direction       = pathGradientMode;
            gradient.Style.CenterXOffset   = 50;
            gradient.Style.CenterYOffset   = 50;
            gradient.Style.Visible         = true;
            gradient.Visible               = true;
        }

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

댓글을 달아 주세요