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 Timer timer;
/// <summary>
/// 파이
/// </summary>
private Pie pie;
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainForm()
/// <summary>
/// 생성자
/// </summary>
public MainForm()
{
InitializeComponent();
Text = "TChart 클래스 : BeforeDrawSeries 이벤트를 사용해 파이 차트에서 커스텀 그림자 그리기";
#region 애니메이션 콤보 박스를 설정한다.
this.animationComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
this.animationComboBox.Items.Add("정지");
this.animationComboBox.Items.Add("저속");
this.animationComboBox.Items.Add("고속");
this.animationComboBox.SelectedIndex = 0;
#endregion
#region 티차트를 설정한다.
this.tChart.Panel.Pen = new ChartPen(Color.Black);
this.tChart.Legend.Visible = false;
#endregion
#region 파이 시리즈를 설정한다.
this.pie = new Pie();
this.pie.Circled = false;
this.pie.FillSampleValues();
this.tChart.Series.Add(this.pie);
#endregion
#region 타이머를 설정한다.
this.timer = new Timer();
this.timer.Interval = 200;
#endregion
#region 이벤트를 설정한다.
this.showShadowCheckBox.CheckedChanged += showShadowCheckBox_CheckedChanged;
this.animationComboBox.SelectedIndexChanged += animationComboBox_SelectedIndexChanged;
this.tChart.BeforeDrawSeries += tChart_BeforeDrawSeries;
this.timer.Tick += timer_Tick;
#endregion
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
//////////////////////////////////////////////////////////////////////////////// Event
#region 그림자 표시 체크 박스 체크 변경시 처리하기 - showShadowCheckBox_CheckedChanged(sender, e)
/// <summary>
/// 그림자 표시 체크 박스 체크 변경시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void showShadowCheckBox_CheckedChanged(object sender, EventArgs e)
{
this.tChart.Refresh();
}
#endregion
#region 애니메이션 콤보 박스 선택 인덱스 변경시 처리하기 - animationComboBox_SelectedIndexChanged(sender, e)
/// <summary>
/// 애니메이션 콤보 박스 선택 인덱스 변경시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void animationComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
switch(this.animationComboBox.SelectedIndex)
{
case 0 :
this.timer.Stop();
break;
case 1 :
this.timer.Interval = 200;
this.timer.Start();
break;
case 2 :
this.timer.Interval = 1;
this.timer.Start();
break;
}
}
#endregion
#region TChart 시리즈 그리기 전 처리하기 - tChart_BeforeDrawSeries(sender, graphics3D)
/// <summary>
/// TChart 시리즈 그리기 전 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="graphics3D">그래픽스 3D</param>
private void tChart_BeforeDrawSeries(object sender, Graphics3D graphics3D)
{
Rectangle rectangle;
if(this.showShadowCheckBox.Checked)
{
rectangle = this.tChart.Chart.ChartRect;
rectangle = Rectangle.FromLTRB
(
rectangle.Left + 80,
rectangle.Bottom - 40,
rectangle.Right - 80,
rectangle.Bottom
);
DrawEllipseShadow(graphics3D, this.tChart.Panel.Color, rectangle);
}
}
#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.pie.RotationAngle = this.pie.RotationAngle + 1;
}
#endregion
//////////////////////////////////////////////////////////////////////////////// Function
#region 타원 그림자 그리기 - DrawEllipseShadow(graphics3D, color, rectangle)
/// <summary>
/// 타원 그림자 그리기
/// </summary>
/// <param name="graphics3D">그래픽스 3D</param>
/// <param name="color">색상</param>
/// <param name="rectangle">사각형</param>
private void DrawEllipseShadow(Graphics3D graphics3D, Color color, Rectangle rectangle)
{
int x;
int y;
int StepCount;
double temporaryWidth;
double temporaryHeight;
graphics3D.Pen.Visible = false;
graphics3D.Brush.Solid = true;
graphics3D.Brush.Visible = true;
graphics3D.Brush.Color = color;
x = (rectangle.Left + rectangle.Right ) / 2;
y = (rectangle.Top + rectangle.Bottom) / 2;
StepCount = Math.Min(x, y) / 10;
temporaryWidth = 0.5 * (rectangle.Right - rectangle.Left) / StepCount;
temporaryHeight = 0.5 * (rectangle.Bottom - rectangle.Top ) / StepCount;
for(int i = StepCount; i > 0; --i)
{
Graphics3D.ApplyDark(ref color, 8);
graphics3D.Brush.Color = color;
rectangle = Rectangle.FromLTRB
(
x - Convert.ToInt32(i * temporaryWidth ),
y - Convert.ToInt32(i * temporaryHeight),
x + Convert.ToInt32(i * temporaryWidth ),
y + Convert.ToInt32(i * temporaryHeight)
);
graphics3D.Ellipse(rectangle);
}
}
#endregion
}
}