using System;
using System.Drawing;
using System.Windows.Forms;
using Steema.TeeChart;
using Steema.TeeChart.Drawing;
using Steema.TeeChart.Styles;
using Steema.TeeChart.Tools;
namespace TestProject
{
/// <summary>
/// 메인 폼
/// </summary>
public partial class MainForm : Form
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainForm()
/// <summary>
/// 생성자
/// </summary>
public MainForm()
{
InitializeComponent();
Text = "GanttTool 클래스 : 간트 차트에서 마우스 드래그 사용하기";
this.dateTimeStepsComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
this.dateTimeStepsComboBox.Items.Add("One day" );
this.dateTimeStepsComboBox.Items.Add("One week" );
this.dateTimeStepsComboBox.Items.Add("Half month");
this.dateTimeStepsComboBox.Items.Add("One month" );
this.dateTimeStepsComboBox.SelectedIndex = 0;
this.tChart.Panel.Pen = new ChartPen(Color.Black);
this.tChart.Axes.Bottom.Increment = Convert.ToDouble(DateTimeSteps.OneDay);
this.tChart.Axes.Bottom.Labels.Angle = 90;
this.tChart.Axes.Bottom.Labels.DateTimeFormat = "yyyy-MM-dd";
this.tChart.Axes.Left.Grid.Centered = false;
this.tChart.Zoom.Direction = ZoomDirections.None;
this.tChart.Axes.Bottom.SetMinMax(new DateTime(2002, 4, 1), new DateTime(2002, 5, 1));
this.tChart.Axes.Left.SetMinMax( -2, 5 );
Gantt gantt = new Gantt(this.tChart.Chart);
gantt.XValues.Order = ValueListOrder.None;
gantt.Marks.Gradient.Visible = true;
gantt.Marks.Shadow.Width = 0;
gantt.Marks.Shadow.Height = 0;
gantt.Marks.Visible = true;
gantt.Add(new DateTime(2002, 4, 1), new DateTime(2002, 4, 10), 0, "A");
gantt.Add(new DateTime(2002, 4, 5), new DateTime(2002, 4, 15), 1, "B");
gantt.Add(new DateTime(2002, 4, 2), new DateTime(2002, 4, 8 ), 2, "C");
gantt.Add(new DateTime(2002, 4, 9), new DateTime(2002, 4, 21), 3, "D");
GanttTool ganttTool = new GanttTool(this.tChart.Chart);
ganttTool.Series = gantt;
this.dateTimeStepsComboBox.SelectedIndexChanged += dateTimeStepsComboBox_SelectedIndexChanged;
this.scrollLeftButton.Click += scrollLeftButton_Click;
this.scrollRightButton.Click += scrollRightButton_Click;
this.zoomInButton.Click += zoomInButton_Click;
this.zoomOutButton.Click += zoomOutButton_Click;
this.tChart.MouseUp += tChart_MouseUp;
gantt.GetSeriesMark += gantt_GetSeriesMark;
ganttTool.DragBar += ganttTool_DragBar;
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
#region 날짜/시간 단계 콤보 박스 선택 인덱스 변경시 처리하기 - dateTimeStepsComboBox_SelectedIndexChanged(sender, e)
/// <summary>
/// 날짜/시간 단계 콤보 박스 선택 인덱스 변경시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void dateTimeStepsComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
switch(this.dateTimeStepsComboBox.SelectedIndex)
{
case 0 : this.tChart.Axes.Bottom.Increment = Convert.ToDouble(DateTimeSteps.OneDay ); break;
case 1 : this.tChart.Axes.Bottom.Increment = Convert.ToDouble(DateTimeSteps.OneWeek ); break;
case 2 : this.tChart.Axes.Bottom.Increment = Convert.ToDouble(DateTimeSteps.HalfMonth); break;
case 3 : this.tChart.Axes.Bottom.Increment = Convert.ToDouble(DateTimeSteps.OneMonth ); break;
}
}
#endregion
#region 왼쪽 스크롤 버튼 클릭시 처리하기 - scrollLeftButton_Click(sender, e)
/// <summary>
/// 왼쪽 스크롤 버튼 클릭시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void scrollLeftButton_Click(object sender, EventArgs e)
{
this.tChart.Axes.Bottom.Scroll(1, false);
}
#endregion
#region 오른쪽 스크롤 버튼 클릭시 처리하기 - scrollRightButton_Click(sender, e)
/// <summary>
/// 오른쪽 스크롤 버튼 클릭시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void scrollRightButton_Click(object sender, EventArgs e)
{
this.tChart.Axes.Bottom.Scroll(-1, false);
}
#endregion
#region 확대 버튼 클릭시 처리하기 - zoomInButton_Click(sender, e)
/// <summary>
/// 확대 버튼 클릭시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void zoomInButton_Click(object sender, EventArgs e)
{
this.tChart.Axes.Bottom.SetMinMax(this.tChart.Axes.Bottom.Minimum + 1, this.tChart.Axes.Bottom.Maximum - 1);
}
#endregion
#region 축소 버튼 클릭시 처리하기 - zoomOutButton_Click(sender, e)
/// <summary>
/// 축소 버튼 클릭시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void zoomOutButton_Click(object sender, EventArgs e)
{
this.tChart.Axes.Bottom.SetMinMax(this.tChart.Axes.Bottom.Minimum - 1, this.tChart.Axes.Bottom.Maximum + 1);
}
#endregion
#region TChart 마우스 UP 처리하기 - tChart_MouseUp(sender, e)
/// <summary>
/// TChart 마우스 UP 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void tChart_MouseUp(object sender, MouseEventArgs e)
{
this.tChart.Header.Text = "TeeChart";
}
#endregion
#region 간트 시리즈 마크 구하기 - gantt_GetSeriesMark(sender, e)
/// <summary>
/// 간트 시리즈 마크 구하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void gantt_GetSeriesMark(Series series, GetSeriesMarkEventArgs e)
{
switch(e.ValueIndex)
{
case 0 : e.MarkText = "John"; break;
case 1 : e.MarkText = "Ann"; break;
case 2 : e.MarkText = "David"; break;
case 3 : e.MarkText = "Carol"; break;
}
}
#endregion
#region 간트 도구 바 드래그시 처리하기 - ganttTool_DragBar(sender, e)
/// <summary>
/// 간트 도구 바 드래그시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void ganttTool_DragBar(object sender, GanttDragEventArgs e)
{
GanttTool ganttTool = sender as GanttTool;
Gantt gantt = ganttTool.Gantt;
this.tChart.Header.Text = $"{DateTime.FromOADate(gantt.StartValues[e.Bar]):MM-dd} ~ {DateTime.FromOADate(gantt.EndValues[e.Bar]):MM-dd}";
}
#endregion
}
}