■ GanttTool 클래스를 사용해 간트 차트에서 마우스 드래그하는 방법을 보여준다.
▶ 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 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
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 } } |