■ Gradient 클래스에서 커스텀 그라디언트를 사용하는 방법을 보여준다.
▶ 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 |
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 } } |