SHOW:
|
|
- or go back to the newest paste.
1 | // ----------------------------------------------------------------------- | |
2 | // <copyright file="GanttChart.cs"> | |
3 | // http://www.codeproject.com/Articles/20731/Gantt-Chart | |
4 | // <summary> | |
5 | // Adds an easy to use Gantt Chart to your application | |
6 | // Created by Adrian "Adagio" Grau | |
7 | // Version 0.55 | |
8 | // </summary> | |
9 | // <remarks></remarks> | |
10 | // </copyright> | |
11 | // ----------------------------------------------------------------------- | |
12 | ||
13 | - | using System; |
13 | + | using System; |
14 | - | using System.Collections.Generic; |
14 | + | using System.Collections.Generic; |
15 | - | using System.Linq; |
15 | + | using System.Linq; |
16 | - | using System.Text; |
16 | + | using System.Text; |
17 | - | using System.Drawing.Drawing2D; |
17 | + | using System.Drawing.Drawing2D; |
18 | - | using System.Drawing; |
18 | + | using System.Drawing; |
19 | - | using System.Windows.Forms; |
19 | + | using System.Windows.Forms; |
20 | ||
21 | /// <summary> | |
22 | - | /// TODO: Update summary. |
22 | + | /// TODO: Update summary. |
23 | /// </summary> | |
24 | - | public class GanttChart : Control |
24 | + | public class GanttChart : Control |
25 | { | |
26 | ||
27 | - | private MouseOverPart mouseHoverPart = MouseOverPart.Empty; |
27 | + | private MouseOverPart mouseHoverPart = MouseOverPart.Empty; |
28 | ||
29 | - | private int mouseHoverBarIndex = -1; |
29 | + | private int mouseHoverBarIndex = -1; |
30 | - | private List<ChartBarDate> bars = new List<ChartBarDate>(); |
30 | + | private List<ChartBarDate> bars = new List<ChartBarDate>(); |
31 | - | private System.DateTime headerFromDate; |
31 | + | private System.DateTime headerFromDate; |
32 | ||
33 | - | private System.DateTime headerToDate; |
33 | + | private System.DateTime headerToDate; |
34 | ||
35 | - | private int barIsChanging = -1; |
35 | + | private int barIsChanging = -1; |
36 | - | private int barStartRight = 20; |
36 | + | private int barStartRight = 20; |
37 | - | private int barStartLeft = 100; |
37 | + | private int barStartLeft = 100; |
38 | - | private int headerTimeStartTop = 30; |
38 | + | private int headerTimeStartTop = 30; |
39 | ||
40 | - | private List<Header> shownHeaderList; |
40 | + | private List<Header> shownHeaderList; |
41 | - | private int barStartTop = 50; |
41 | + | private int barStartTop = 50; |
42 | - | private int barHeight = 9; |
42 | + | private int barHeight = 9; |
43 | ||
44 | - | private int barSpace = 5; |
44 | + | private int barSpace = 5; |
45 | ||
46 | - | private int widthPerItem; |
46 | + | private int widthPerItem; |
47 | - | private System.DateTime _mouseOverColumnValue; |
47 | + | private System.DateTime _mouseOverColumnValue; |
48 | - | private string _mouseOverRowText = ""; |
48 | + | private string _mouseOverRowText = ""; |
49 | ||
50 | - | private object _mouseOverRowValue = null; |
50 | + | private object _mouseOverRowValue = null; |
51 | - | private Pen lineColor = Pens.Bisque; |
51 | + | private Pen lineColor = Pens.Bisque; |
52 | - | private Font dateTextFont = new Font("VERDANA", 8.0f, FontStyle.Regular, GraphicsUnit.Point); |
52 | + | private Font dateTextFont = new Font("VERDANA", 8.0f, FontStyle.Regular, GraphicsUnit.Point); |
53 | - | private Font timeTextFont = new Font("VERDANA", 8.0f, FontStyle.Regular, GraphicsUnit.Point); |
53 | + | private Font timeTextFont = new Font("VERDANA", 8.0f, FontStyle.Regular, GraphicsUnit.Point); |
54 | ||
55 | - | private Font rowTextFont = new Font("VERDANA", 8.0f, FontStyle.Regular, GraphicsUnit.Point); |
55 | + | private Font rowTextFont = new Font("VERDANA", 8.0f, FontStyle.Regular, GraphicsUnit.Point); |
56 | - | private System.Windows.Forms.ToolTip withEventsField_ToolTip = new System.Windows.Forms.ToolTip(); |
56 | + | private System.Windows.Forms.ToolTip withEventsField_ToolTip = new System.Windows.Forms.ToolTip(); |
57 | - | internal System.Windows.Forms.ToolTip ToolTip |
57 | + | internal System.Windows.Forms.ToolTip ToolTip |
58 | { | |
59 | - | get { return withEventsField_ToolTip; } |
59 | + | get { return withEventsField_ToolTip; } |
60 | - | set |
60 | + | set |
61 | { | |
62 | - | if (withEventsField_ToolTip != null) |
62 | + | if (withEventsField_ToolTip != null) |
63 | { | |
64 | - | withEventsField_ToolTip.Draw -= ToolTipText_Draw; |
64 | + | withEventsField_ToolTip.Draw -= ToolTipText_Draw; |
65 | - | withEventsField_ToolTip.Popup -= ToolTipText_Popup; |
65 | + | withEventsField_ToolTip.Popup -= ToolTipText_Popup; |
66 | } | |
67 | - | withEventsField_ToolTip = value; |
67 | + | withEventsField_ToolTip = value; |
68 | - | if (withEventsField_ToolTip != null) |
68 | + | if (withEventsField_ToolTip != null) |
69 | { | |
70 | - | withEventsField_ToolTip.Draw += ToolTipText_Draw; |
70 | + | withEventsField_ToolTip.Draw += ToolTipText_Draw; |
71 | - | withEventsField_ToolTip.Popup += ToolTipText_Popup; |
71 | + | withEventsField_ToolTip.Popup += ToolTipText_Popup; |
72 | } | |
73 | } | |
74 | ||
75 | } | |
76 | ||
77 | - | private bool _allowEditBarWithMouse = false; |
77 | + | private bool _allowEditBarWithMouse = false; |
78 | - | public event MouseDraggedEventHandler MouseDragged; |
78 | + | public event MouseDraggedEventHandler MouseDragged; |
79 | - | public delegate void MouseDraggedEventHandler(object sender, System.Windows.Forms.MouseEventArgs e); |
79 | + | public delegate void MouseDraggedEventHandler(object sender, System.Windows.Forms.MouseEventArgs e); |
80 | - | public event BarChangedEventHandler BarChanged; |
80 | + | public event BarChangedEventHandler BarChanged; |
81 | - | public delegate void BarChangedEventHandler(object sender, object barValue); |
81 | + | public delegate void BarChangedEventHandler(object sender, object barValue); |
82 | public event BarChangingEventHandler BarChanging; | |
83 | - | private Bitmap objBmp; |
83 | + | public delegate void BarChangingEventHandler(object sender, object barValue); |
84 | ||
85 | - | private Graphics objGraphics; |
85 | + | private Bitmap objBmp; |
86 | ||
87 | - | protected new bool DesignMode |
87 | + | private Graphics objGraphics; |
88 | ||
89 | - | get |
89 | + | protected new bool DesignMode |
90 | { | |
91 | - | if (base.DesignMode) |
91 | + | get |
92 | - | return true; |
92 | + | |
93 | if (base.DesignMode) | |
94 | - | return System.ComponentModel.LicenseManager.UsageMode == System.ComponentModel.LicenseUsageMode.Designtime; |
94 | + | return true; |
95 | ||
96 | return System.ComponentModel.LicenseManager.UsageMode == System.ComponentModel.LicenseUsageMode.Designtime; | |
97 | } | |
98 | - | #region "Public properties" |
98 | + | } |
99 | ||
100 | #region "Public properties" | |
101 | - | /// Sets to true if the user should be able to manually edit bars |
101 | + | |
102 | /// <summary> | |
103 | /// Sets to true if the user should be able to manually edit bars | |
104 | /// </summary> | |
105 | /// <value></value> | |
106 | /// <returns></returns> | |
107 | - | public bool AllowManualEditBar |
107 | + | /// <remarks></remarks> |
108 | ||
109 | - | get { return _allowEditBarWithMouse; } |
109 | + | public bool AllowManualEditBar |
110 | - | set { _allowEditBarWithMouse = value; } |
110 | + | |
111 | get { return _allowEditBarWithMouse; } | |
112 | set { _allowEditBarWithMouse = value; } | |
113 | } | |
114 | - | /// The start date/time of the chart |
114 | + | |
115 | /// <summary> | |
116 | /// The start date/time of the chart | |
117 | /// </summary> | |
118 | /// <value></value> | |
119 | /// <returns></returns> | |
120 | - | public System.DateTime FromDate |
120 | + | /// <remarks></remarks> |
121 | ||
122 | - | get { return headerFromDate; } |
122 | + | public System.DateTime FromDate |
123 | - | set { headerFromDate = value; } |
123 | + | |
124 | get { return headerFromDate; } | |
125 | set { headerFromDate = value; } | |
126 | } | |
127 | - | /// The end date/time of the chart |
127 | + | |
128 | /// <summary> | |
129 | /// The end date/time of the chart | |
130 | /// </summary> | |
131 | /// <value></value> | |
132 | /// <returns></returns> | |
133 | - | public System.DateTime ToDate |
133 | + | /// <remarks></remarks> |
134 | ||
135 | - | get { return headerToDate; } |
135 | + | public System.DateTime ToDate |
136 | - | set { headerToDate = value; } |
136 | + | |
137 | get { return headerToDate; } | |
138 | set { headerToDate = value; } | |
139 | } | |
140 | - | /// The text for the current row the mouse hovers above |
140 | + | |
141 | /// <summary> | |
142 | /// The text for the current row the mouse hovers above | |
143 | /// </summary> | |
144 | /// <value></value> | |
145 | /// <returns></returns> | |
146 | - | public string MouseOverRowText |
146 | + | /// <remarks></remarks> |
147 | ||
148 | - | get { return _mouseOverRowText; } |
148 | + | public string MouseOverRowText |
149 | { | |
150 | get { return _mouseOverRowText; } | |
151 | } | |
152 | - | /// The value for the current bar the mouse hovers above |
152 | + | |
153 | /// <summary> | |
154 | /// The value for the current bar the mouse hovers above | |
155 | /// </summary> | |
156 | /// <value></value> | |
157 | /// <returns></returns> | |
158 | - | public object MouseOverRowValue |
158 | + | /// <remarks></remarks> |
159 | ||
160 | - | get { return _mouseOverRowValue; } |
160 | + | public object MouseOverRowValue |
161 | { | |
162 | get { return _mouseOverRowValue; } | |
163 | } | |
164 | - | /// The date/time the mouse hovers above |
164 | + | |
165 | /// <summary> | |
166 | /// The date/time the mouse hovers above | |
167 | /// </summary> | |
168 | /// <value></value> | |
169 | /// <returns></returns> | |
170 | - | public System.DateTime MouseOverColumnDate |
170 | + | /// <remarks></remarks> |
171 | ||
172 | - | get { return _mouseOverColumnValue; } |
172 | + | public System.DateTime MouseOverColumnDate |
173 | { | |
174 | get { return _mouseOverColumnValue; } | |
175 | } | |
176 | - | /// The color of the grid |
176 | + | |
177 | /// <summary> | |
178 | /// The color of the grid | |
179 | /// </summary> | |
180 | /// <value></value> | |
181 | /// <returns></returns> | |
182 | - | public System.Drawing.Pen GridColor |
182 | + | /// <remarks></remarks> |
183 | ||
184 | - | get { return lineColor; } |
184 | + | public System.Drawing.Pen GridColor |
185 | - | set { lineColor = value; } |
185 | + | |
186 | get { return lineColor; } | |
187 | set { lineColor = value; } | |
188 | } | |
189 | - | /// The font used for the row text |
189 | + | |
190 | /// <summary> | |
191 | /// The font used for the row text | |
192 | /// </summary> | |
193 | /// <value></value> | |
194 | /// <returns></returns> | |
195 | - | public Font RowFont |
195 | + | /// <remarks></remarks> |
196 | ||
197 | - | get { return rowTextFont; } |
197 | + | public Font RowFont |
198 | - | set { rowTextFont = value; } |
198 | + | |
199 | get { return rowTextFont; } | |
200 | set { rowTextFont = value; } | |
201 | } | |
202 | - | /// The font used for the "date" text in the columns |
202 | + | |
203 | /// <summary> | |
204 | /// The font used for the "date" text in the columns | |
205 | /// </summary> | |
206 | /// <value></value> | |
207 | /// <returns></returns> | |
208 | - | public Font DateFont |
208 | + | /// <remarks></remarks> |
209 | ||
210 | - | get { return dateTextFont; } |
210 | + | public Font DateFont |
211 | - | set { dateTextFont = value; } |
211 | + | |
212 | get { return dateTextFont; } | |
213 | set { dateTextFont = value; } | |
214 | } | |
215 | - | /// The font used for the "time" text in the colums) |
215 | + | |
216 | /// <summary> | |
217 | /// The font used for the "time" text in the colums) | |
218 | /// </summary> | |
219 | /// <value></value> | |
220 | /// <returns></returns> | |
221 | - | public Font TimeFont |
221 | + | /// <remarks></remarks> |
222 | ||
223 | - | get { return timeTextFont; } |
223 | + | public Font TimeFont |
224 | - | set { timeTextFont = value; } |
224 | + | |
225 | get { return timeTextFont; } | |
226 | set { timeTextFont = value; } | |
227 | - | #endregion |
227 | + | } |
228 | ||
229 | - | #region "Constructor" |
229 | + | #endregion |
230 | ||
231 | #region "Constructor" | |
232 | - | /// Default constructor |
232 | + | |
233 | /// <summary> | |
234 | /// Default constructor | |
235 | /// </summary> | |
236 | - | public GanttChart() |
236 | + | /// <remarks></remarks> |
237 | ||
238 | - | if (!DesignMode) |
238 | + | public GanttChart() |
239 | { | |
240 | MouseWheel += GanttChart_MouseWheel; | |
241 | - | MouseWheel += GanttChart_MouseWheel; |
241 | + | MouseClick += GanttChart_Click; |
242 | - | MouseClick += GanttChart_Click; |
242 | + | MouseDragged += GanttChart_MouseDragged; |
243 | - | MouseDragged += GanttChart_MouseDragged; |
243 | + | MouseLeave += GanttChart_MouseLeave; |
244 | - | MouseLeave += GanttChart_MouseLeave; |
244 | + | MouseMove += GanttChart_MouseMove; |
245 | - | MouseMove += GanttChart_MouseMove; |
245 | + | ToolTip.AutoPopDelay = 15000; |
246 | - | ToolTip.AutoPopDelay = 15000; |
246 | + | ToolTip.InitialDelay = 250; |
247 | - | ToolTip.InitialDelay = 250; |
247 | + | ToolTip.OwnerDraw = true; |
248 | - | ToolTip.OwnerDraw = true; |
248 | + | objBmp = new Bitmap(1280, 1024, System.Drawing.Imaging.PixelFormat.Format24bppRgb); |
249 | objGraphics = Graphics.FromImage(objBmp); | |
250 | - | objBmp = new Bitmap(1280, 1024, System.Drawing.Imaging.PixelFormat.Format24bppRgb); |
250 | + | if (!DesignMode) |
251 | - | objGraphics = Graphics.FromImage(objBmp); |
251 | + | |
252 | // Flicker free drawing | |
253 | - | // Flicker free drawing |
253 | + | this.SetStyle(ControlStyles.DoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true); |
254 | } | |
255 | - | this.SetStyle(ControlStyles.DoubleBuffer | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true); |
255 | + | |
256 | } | |
257 | ||
258 | #endregion | |
259 | ||
260 | - | #endregion |
260 | + | #region "Bars" |
261 | ||
262 | - | #region "Bars" |
262 | + | private void SetBarStartLeft(string rowText) |
263 | { | |
264 | - | private void SetBarStartLeft(string rowText) |
264 | + | Graphics gfx = this.CreateGraphics(); |
265 | ||
266 | - | Graphics gfx = this.CreateGraphics(); |
266 | + | int length = Convert.ToInt32(gfx.MeasureString(rowText, rowTextFont, 500).Width); |
267 | ||
268 | - | int length = Convert.ToInt32(gfx.MeasureString(rowText, rowTextFont, 500).Width); |
268 | + | if (length > barStartLeft) |
269 | { | |
270 | - | if (length > barStartLeft) |
270 | + | barStartLeft = length; |
271 | } | |
272 | - | barStartLeft = length; |
272 | + | } |
273 | ||
274 | /// <summary> | |
275 | /// Adds a bar to the list | |
276 | /// </summary> | |
277 | - | /// Adds a bar to the list |
277 | + | /// <param name="rowText">Text for the row</param> |
278 | /// <param name="barValue">Value for the row</param> | |
279 | - | /// <param name="rowText">Text for the row</param> |
279 | + | /// <param name="fromTime">The date/time the bar starts</param> |
280 | - | /// <param name="barValue">Value for the row</param> |
280 | + | /// <param name="toTime">The date/time the bar ends</param> |
281 | - | /// <param name="fromTime">The date/time the bar starts</param> |
281 | + | /// <param name="color">The color of the bar</param> |
282 | - | /// <param name="toTime">The date/time the bar ends</param> |
282 | + | /// <param name="hoverColor">The hover color of the bar</param> |
283 | - | /// <param name="color">The color of the bar</param> |
283 | + | /// <param name="rowIndex">The rowindex of the bar (useful if you want several bars on the same row)</param> |
284 | - | /// <param name="hoverColor">The hover color of the bar</param> |
284 | + | /// <remarks></remarks> |
285 | - | /// <param name="rowIndex">The rowindex of the bar (useful if you want several bars on the same row)</param> |
285 | + | |
286 | public void AddChartBar(string rowText, object barValue, System.DateTime fromTime, System.DateTime toTime, Color color, Color hoverColor, int rowIndex) | |
287 | { | |
288 | - | public void AddChartBar(string rowText, object barValue, System.DateTime fromTime, System.DateTime toTime, Color color, Color hoverColor, int rowIndex) |
288 | + | ChartBarDate bar = new ChartBarDate(); |
289 | bar.Text = rowText; | |
290 | - | ChartBarDate bar = new ChartBarDate(); |
290 | + | bar.Value = barValue; |
291 | - | bar.Text = rowText; |
291 | + | bar.StartValue = fromTime; |
292 | - | bar.Value = barValue; |
292 | + | bar.EndValue = toTime; |
293 | - | bar.StartValue = fromTime; |
293 | + | bar.Color = color; |
294 | - | bar.EndValue = toTime; |
294 | + | bar.HoverColor = hoverColor; |
295 | - | bar.Color = color; |
295 | + | bar.RowIndex = rowIndex; |
296 | - | bar.HoverColor = hoverColor; |
296 | + | bars.Add(bar); |
297 | - | bar.RowIndex = rowIndex; |
297 | + | |
298 | - | bars.Add(bar); |
298 | + | SetBarStartLeft(rowText); |
299 | } | |
300 | - | SetBarStartLeft(rowText); |
300 | + | |
301 | /// <summary> | |
302 | /// Adds a bar to the list | |
303 | /// </summary> | |
304 | - | /// Adds a bar to the list |
304 | + | /// <param name="rowText">Text for the row</param> |
305 | /// <param name="barValue">Value for the row</param> | |
306 | - | /// <param name="rowText">Text for the row</param> |
306 | + | /// <param name="fromTime">The date/time the bar starts</param> |
307 | - | /// <param name="barValue">Value for the row</param> |
307 | + | /// <param name="toTime">The date/time the bar ends</param> |
308 | - | /// <param name="fromTime">The date/time the bar starts</param> |
308 | + | /// <param name="color">The color of the bar</param> |
309 | - | /// <param name="toTime">The date/time the bar ends</param> |
309 | + | /// <param name="hoverColor">The hover color of the bar</param> |
310 | - | /// <param name="color">The color of the bar</param> |
310 | + | /// <param name="rowIndex">The rowindex of the bar (useful if you want several bars on the same row)</param> |
311 | - | /// <param name="hoverColor">The hover color of the bar</param> |
311 | + | /// <param name="hideFromMouseMove">If you want to "hide" the bar from mousemove event</param> |
312 | - | /// <param name="rowIndex">The rowindex of the bar (useful if you want several bars on the same row)</param> |
312 | + | /// <remarks></remarks> |
313 | - | /// <param name="hideFromMouseMove">If you want to "hide" the bar from mousemove event</param> |
313 | + | |
314 | public void AddChartBar(string rowText, object barValue, System.DateTime fromTime, System.DateTime toTime, Color color, Color hoverColor, int rowIndex, bool hideFromMouseMove) | |
315 | { | |
316 | - | public void AddChartBar(string rowText, object barValue, System.DateTime fromTime, System.DateTime toTime, Color color, Color hoverColor, int rowIndex, bool hideFromMouseMove) |
316 | + | ChartBarDate bar = new ChartBarDate(); |
317 | bar.Text = rowText; | |
318 | - | ChartBarDate bar = new ChartBarDate(); |
318 | + | bar.Value = barValue; |
319 | - | bar.Text = rowText; |
319 | + | bar.StartValue = fromTime; |
320 | - | bar.Value = barValue; |
320 | + | bar.EndValue = toTime; |
321 | - | bar.StartValue = fromTime; |
321 | + | bar.Color = color; |
322 | - | bar.EndValue = toTime; |
322 | + | bar.HoverColor = hoverColor; |
323 | - | bar.Color = color; |
323 | + | bar.RowIndex = rowIndex; |
324 | - | bar.HoverColor = hoverColor; |
324 | + | bar.HideFromMouseMove = hideFromMouseMove; |
325 | - | bar.RowIndex = rowIndex; |
325 | + | bars.Add(bar); |
326 | - | bar.HideFromMouseMove = hideFromMouseMove; |
326 | + | |
327 | - | bars.Add(bar); |
327 | + | SetBarStartLeft(rowText); |
328 | } | |
329 | - | SetBarStartLeft(rowText); |
329 | + | |
330 | /// <summary> | |
331 | /// Gets the next index | |
332 | /// </summary> | |
333 | - | /// Gets the next index |
333 | + | /// <param name="rowText"></param> |
334 | /// <returns></returns> | |
335 | - | /// <param name="rowText"></param> |
335 | + | /// <remarks></remarks> |
336 | ||
337 | public int GetIndexChartBar(string rowText) | |
338 | { | |
339 | - | public int GetIndexChartBar(string rowText) |
339 | + | int index = -1; |
340 | ||
341 | - | int index = -1; |
341 | + | foreach (ChartBarDate bar in bars) |
342 | { | |
343 | if (bar.Text.Equals(rowText) == true) | |
344 | { | |
345 | - | if (bar.Text.Equals(rowText) == true) |
345 | + | return bar.RowIndex; |
346 | } | |
347 | - | return bar.RowIndex; |
347 | + | if (bar.RowIndex > index) |
348 | { | |
349 | - | if (bar.RowIndex > index) |
349 | + | |
350 | } | |
351 | - | index = bar.RowIndex; |
351 | + | |
352 | ||
353 | return index + 1; | |
354 | } | |
355 | - | return index + 1; |
355 | + | |
356 | /// <summary> | |
357 | /// Removes all bars from list | |
358 | /// </summary> | |
359 | - | /// Removes all bars from list |
359 | + | /// <remarks></remarks> |
360 | ||
361 | public void RemoveBars() | |
362 | { | |
363 | - | public void RemoveBars() |
363 | + | bars = new List<ChartBarDate>(); |
364 | ||
365 | - | bars = new List<ChartBarDate>(); |
365 | + | barStartLeft = 100; |
366 | } | |
367 | - | barStartLeft = 100; |
367 | + | |
368 | #endregion | |
369 | ||
370 | - | #endregion |
370 | + | #region "Draw" |
371 | ||
372 | - | #region "Draw" |
372 | + | |
373 | /// Redraws the Gantt chart | |
374 | /// </summary> | |
375 | - | /// Redraws the Gantt chart |
375 | + | /// <remarks></remarks> |
376 | ||
377 | public void PaintChart() | |
378 | { | |
379 | - | public void PaintChart() |
379 | + | this.Invalidate(); |
380 | } | |
381 | - | this.Invalidate(); |
381 | + | |
382 | /// <summary> | |
383 | /// Redraws the Gantt chart | |
384 | /// </summary> | |
385 | - | /// Redraws the Gantt chart |
385 | + | /// <param name="gfx"></param> |
386 | /// <remarks></remarks> | |
387 | - | /// <param name="gfx"></param> |
387 | + | |
388 | private void PaintChart(Graphics gfx) | |
389 | { | |
390 | - | private void PaintChart(Graphics gfx) |
390 | + | gfx.Clear(this.BackColor); |
391 | ||
392 | - | gfx.Clear(this.BackColor); |
392 | + | if (headerFromDate == null | headerToDate == null) |
393 | return; | |
394 | - | if (headerFromDate == null | headerToDate == null) |
394 | + | |
395 | DrawScrollBar(gfx); | |
396 | DrawHeader(gfx, null); | |
397 | - | DrawScrollBar(gfx); |
397 | + | DrawNetHorizontal(gfx); |
398 | - | DrawHeader(gfx, null); |
398 | + | DrawNetVertical(gfx); |
399 | - | DrawNetHorizontal(gfx); |
399 | + | DrawBars(gfx); |
400 | - | DrawNetVertical(gfx); |
400 | + | |
401 | - | DrawBars(gfx); |
401 | + | objBmp = new Bitmap(this.Width - barStartRight, lastLineStop, System.Drawing.Imaging.PixelFormat.Format24bppRgb); |
402 | objGraphics = Graphics.FromImage(objBmp); | |
403 | } | |
404 | ||
405 | /// <summary> | |
406 | /// Redraws the Gantt chart | |
407 | /// </summary> | |
408 | - | /// Redraws the Gantt chart |
408 | + | /// <param name="pe"></param> |
409 | /// <remarks></remarks> | |
410 | - | /// <param name="pe"></param> |
410 | + | |
411 | protected override void OnPaint(System.Windows.Forms.PaintEventArgs pe) | |
412 | { | |
413 | - | protected override void OnPaint(System.Windows.Forms.PaintEventArgs pe) |
413 | + | base.OnPaint(pe); |
414 | if (!DesignMode) | |
415 | - | base.OnPaint(pe); |
415 | + | |
416 | - | if (!DesignMode) |
416 | + | PaintChart(pe.Graphics); |
417 | } | |
418 | - | PaintChart(pe.Graphics); |
418 | + | } |
419 | ||
420 | /// <summary> | |
421 | /// Draws the list of headers. Automatically shows which headers to draw, based on the width of the Gantt Chart | |
422 | /// </summary> | |
423 | - | /// Draws the list of headers. Automatically shows which headers to draw, based on the width of the Gantt Chart |
423 | + | /// <param name="gfx"></param> |
424 | /// <param name="headerList"></param> | |
425 | - | /// <param name="gfx"></param> |
425 | + | /// <remarks></remarks> |
426 | - | /// <param name="headerList"></param> |
426 | + | |
427 | private void DrawHeader(Graphics gfx, List<Header> headerList) | |
428 | { | |
429 | - | private void DrawHeader(Graphics gfx, List<Header> headerList) |
429 | + | if (headerList == null) |
430 | { | |
431 | - | if (headerList == null) |
431 | + | headerList = GetFullHeaderList(); |
432 | } | |
433 | - | headerList = GetFullHeaderList(); |
433 | + | |
434 | if (headerList.Count == 0) | |
435 | return; | |
436 | - | if (headerList.Count == 0) |
436 | + | |
437 | dynamic availableWidth = this.Width - 10 - barStartLeft - barStartRight; | |
438 | widthPerItem = availableWidth / headerList.Count; | |
439 | - | dynamic availableWidth = this.Width - 10 - barStartLeft - barStartRight; |
439 | + | |
440 | - | widthPerItem = availableWidth / headerList.Count; |
440 | + | if (widthPerItem < 40) |
441 | { | |
442 | - | if (widthPerItem < 40) |
442 | + | List<Header> newHeaderList = new List<Header>(); |
443 | ||
444 | - | List<Header> newHeaderList = new List<Header>(); |
444 | + | bool showNext = true; |
445 | ||
446 | - | bool showNext = true; |
446 | + | // If there's not enough room for all headers remove 50% |
447 | ||
448 | - | // If there's not enough room for all headers remove 50% |
448 | + | |
449 | { | |
450 | - | foreach (Header header in headerList) |
450 | + | if (showNext == true) |
451 | { | |
452 | - | if (showNext == true) |
452 | + | newHeaderList.Add(header); |
453 | showNext = false; | |
454 | - | newHeaderList.Add(header); |
454 | + | |
455 | - | showNext = false; |
455 | + | |
456 | { | |
457 | - | else |
457 | + | showNext = true; |
458 | } | |
459 | - | showNext = true; |
459 | + | |
460 | ||
461 | DrawHeader(gfx, newHeaderList); | |
462 | return; | |
463 | - | DrawHeader(gfx, newHeaderList); |
463 | + | |
464 | ||
465 | int index = 0; | |
466 | int headerStartPosition = -1; | |
467 | Header lastHeader = null; | |
468 | - | int headerStartPosition = -1; |
468 | + | |
469 | - | Header lastHeader = null; |
469 | + | foreach (Header header in headerList) |
470 | { | |
471 | int startPos = barStartLeft + (index * widthPerItem); | |
472 | bool showDateHeader = false; | |
473 | - | int startPos = barStartLeft + (index * widthPerItem); |
473 | + | |
474 | - | bool showDateHeader = false; |
474 | + | header.StartLocation = startPos; |
475 | ||
476 | - | header.StartLocation = startPos; |
476 | + | // Checks whether to show the date or not |
477 | ||
478 | - | // Checks whether to show the date or not |
478 | + | if (lastHeader == null) |
479 | { | |
480 | - | if (lastHeader == null) |
480 | + | showDateHeader = true; |
481 | } | |
482 | - | showDateHeader = true; |
482 | + | else if (header.Time.Hour < lastHeader.Time.Hour) |
483 | { | |
484 | - | else if (header.Time.Hour < lastHeader.Time.Hour) |
484 | + | showDateHeader = true; |
485 | } | |
486 | - | showDateHeader = true; |
486 | + | else if (header.Time.Minute == lastHeader.Time.Minute) |
487 | { | |
488 | - | else if (header.Time.Minute == lastHeader.Time.Minute) |
488 | + | showDateHeader = true; |
489 | } | |
490 | - | showDateHeader = true; |
490 | + | |
491 | // Show date | |
492 | ||
493 | - | // Show date |
493 | + | if (showDateHeader == true) |
494 | { | |
495 | - | if (showDateHeader == true) |
495 | + | string str = ""; |
496 | ||
497 | - | string str = ""; |
497 | + | if (header.HeaderTextInsteadOfTime.Length > 0) |
498 | { | |
499 | - | if (header.HeaderTextInsteadOfTime.Length > 0) |
499 | + | str = header.HeaderTextInsteadOfTime; |
500 | } | |
501 | - | str = header.HeaderTextInsteadOfTime; |
501 | + | |
502 | { | |
503 | - | else |
503 | + | str = header.Time.ToString("d-MMM"); |
504 | } | |
505 | - | str = header.Time.ToString("d-MMM"); |
505 | + | gfx.DrawString(str, dateTextFont, Brushes.Black, startPos, 0); |
506 | } | |
507 | - | gfx.DrawString(str, dateTextFont, Brushes.Black, startPos, 0); |
507 | + | |
508 | // Show time | |
509 | ||
510 | - | // Show time |
510 | + | gfx.DrawString(header.HeaderText, timeTextFont, Brushes.Black, startPos, headerTimeStartTop); |
511 | index += 1; | |
512 | - | gfx.DrawString(header.HeaderText, timeTextFont, Brushes.Black, startPos, headerTimeStartTop); |
512 | + | |
513 | lastHeader = header; | |
514 | } | |
515 | - | lastHeader = header; |
515 | + | |
516 | shownHeaderList = headerList; | |
517 | widthPerItem = (this.Width - 10 - barStartLeft - barStartRight) / shownHeaderList.Count; | |
518 | - | shownHeaderList = headerList; |
518 | + | } |
519 | - | widthPerItem = (this.Width - 10 - barStartLeft - barStartRight) / shownHeaderList.Count; |
519 | + | |
520 | /// <summary> | |
521 | /// Draws the bars | |
522 | /// </summary> | |
523 | - | /// Draws the bars |
523 | + | /// <param name="grfx"></param> |
524 | /// <remarks></remarks> | |
525 | - | /// <param name="grfx"></param> |
525 | + | |
526 | private void DrawBars(Graphics grfx, bool ignoreScrollAndMousePosition = false) | |
527 | { | |
528 | - | private void DrawBars(Graphics grfx, bool ignoreScrollAndMousePosition = false) |
528 | + | if (shownHeaderList == null) |
529 | return; | |
530 | - | if (shownHeaderList == null) |
530 | + | if (shownHeaderList.Count == 0) |
531 | return; | |
532 | - | if (shownHeaderList.Count == 0) |
532 | + | |
533 | int index = 0; | |
534 | ||
535 | // Finds pixels per minute | |
536 | ||
537 | - | // Finds pixels per minute |
537 | + | TimeSpan timeBetween = shownHeaderList[1].Time - shownHeaderList[0].Time; |
538 | int minutesBetween = Convert.ToInt32(timeBetween.TotalMinutes); | |
539 | - | TimeSpan timeBetween = shownHeaderList[1].Time - shownHeaderList[0].Time; |
539 | + | //(timeBetween.Days * 1440) + (timeBetween.Hours * 60) + timeBetween.Minutes |
540 | - | int minutesBetween = Convert.ToInt32(timeBetween.TotalMinutes); |
540 | + | dynamic widthBetween = (shownHeaderList[1].StartLocation - shownHeaderList[0].StartLocation); |
541 | - | //(timeBetween.Days * 1440) + (timeBetween.Hours * 60) + timeBetween.Minutes |
541 | + | decimal perMinute = Convert.ToDecimal(widthBetween) / Convert.ToDecimal(minutesBetween); |
542 | - | dynamic widthBetween = (shownHeaderList[1].StartLocation - shownHeaderList[0].StartLocation); |
542 | + | |
543 | - | decimal perMinute = widthBetween / minutesBetween; |
543 | + | // Draws each bar |
544 | ||
545 | - | // Draws each bar |
545 | + | foreach (ChartBarDate bar in bars) |
546 | { | |
547 | index = bar.RowIndex; | |
548 | ||
549 | int startLocation = 0; | |
550 | int width = 0; | |
551 | - | int startLocation = 0; |
551 | + | int startMinutes = 0; |
552 | - | int width = 0; |
552 | + | // Number of minutes from start of the gantt chart |
553 | - | int startMinutes = 0; |
553 | + | TimeSpan startTimeSpan = default(TimeSpan); |
554 | - | // Number of minutes from start of the gantt chart |
554 | + | int lengthMinutes = 0; |
555 | - | TimeSpan startTimeSpan = default(TimeSpan); |
555 | + | // Number of minutes from bar start to bar end |
556 | - | int lengthMinutes = 0; |
556 | + | TimeSpan lengthTimeSpan = default(TimeSpan); |
557 | - | // Number of minutes from bar start to bar end |
557 | + | |
558 | - | TimeSpan lengthTimeSpan = default(TimeSpan); |
558 | + | int scrollPos = 0; |
559 | ||
560 | - | int scrollPos = 0; |
560 | + | if (ignoreScrollAndMousePosition == false) |
561 | { | |
562 | - | if (ignoreScrollAndMousePosition == false) |
562 | + | scrollPos = scrollPosition; |
563 | } | |
564 | - | scrollPos = scrollPosition; |
564 | + | |
565 | // Calculates where the bar should be located | |
566 | ||
567 | - | // Calculates where the bar should be located |
567 | + | startTimeSpan = bar.StartValue - FromDate; |
568 | startMinutes = (startTimeSpan.Days * 1440) + (startTimeSpan.Hours * 60) + startTimeSpan.Minutes; | |
569 | - | startTimeSpan = bar.StartValue - FromDate; |
569 | + | |
570 | - | startMinutes = (startTimeSpan.Days * 1440) + (startTimeSpan.Hours * 60) + startTimeSpan.Minutes; |
570 | + | startLocation = Convert.ToInt32(perMinute * startMinutes); |
571 | ||
572 | - | startLocation = Convert.ToInt32(perMinute * startMinutes); |
572 | + | System.DateTime endValue = bar.EndValue; |
573 | ||
574 | - | System.DateTime endValue = bar.EndValue; |
574 | + | if (endValue == null) |
575 | { | |
576 | - | if (endValue == null) |
576 | + | endValue = System.DateTime.Now; |
577 | } | |
578 | - | endValue = System.DateTime.Now; |
578 | + | |
579 | lengthTimeSpan = endValue - bar.StartValue; | |
580 | lengthMinutes = (lengthTimeSpan.Days * 1440) + (lengthTimeSpan.Hours * 60) + lengthTimeSpan.Minutes; | |
581 | - | lengthTimeSpan = endValue - bar.StartValue; |
581 | + | |
582 | - | lengthMinutes = (lengthTimeSpan.Days * 1440) + (lengthTimeSpan.Hours * 60) + lengthTimeSpan.Minutes; |
582 | + | width = Convert.ToInt32(perMinute * lengthMinutes); |
583 | ||
584 | - | width = Convert.ToInt32(perMinute * lengthMinutes); |
584 | + | int a = barStartLeft + startLocation; |
585 | int b = barStartTop + (barHeight * (index - scrollPos)) + (barSpace * (index - scrollPos)) + 2; | |
586 | - | int a = barStartLeft + startLocation; |
586 | + | int c = width; |
587 | - | int b = barStartTop + (barHeight * (index - scrollPos)) + (barSpace * (index - scrollPos)) + 2; |
587 | + | int d = barHeight; |
588 | - | int c = width; |
588 | + | |
589 | - | int d = barHeight; |
589 | + | if (c == 0) |
590 | c = 1; | |
591 | - | if (c == 0) |
591 | + | |
592 | - | c = 1; |
592 | + | // Stops a bar from going into the row-text area |
593 | ||
594 | - | // Stops a bar from going into the row-text area |
594 | + | if (a - barStartLeft < 0) |
595 | { | |
596 | - | if (a - barStartLeft < 0) |
596 | + | a = barStartLeft; |
597 | } | |
598 | - | a = barStartLeft; |
598 | + | |
599 | System.Drawing.Color color = default(System.Drawing.Color); | |
600 | ||
601 | - | System.Drawing.Color color = default(System.Drawing.Color); |
601 | + | // If mouse is over bar, set the color to be hovercolor |
602 | ||
603 | - | // If mouse is over bar, set the color to be hovercolor |
603 | + | if (MouseOverRowText == bar.Text & bar.StartValue <= _mouseOverColumnValue & bar.EndValue >= _mouseOverColumnValue) |
604 | { | |
605 | - | if (MouseOverRowText == bar.Text & bar.StartValue <= _mouseOverColumnValue & bar.EndValue >= _mouseOverColumnValue) |
605 | + | color = bar.HoverColor; |
606 | } | |
607 | - | color = bar.HoverColor; |
607 | + | |
608 | { | |
609 | color = bar.Color; | |
610 | } | |
611 | - | color = bar.Color; |
611 | + | |
612 | // Set the location for the graphics | |
613 | ||
614 | - | // Set the location for the graphics |
614 | + | bar.TopLocation.Left = new Point(a, b); |
615 | bar.TopLocation.Right = new Point(a + c, b); | |
616 | - | bar.TopLocation.Left = new Point(a, b); |
616 | + | bar.BottomLocation.Left = new Point(a, b + d); |
617 | - | bar.TopLocation.Right = new Point(a + c, b); |
617 | + | bar.BottomLocation.Right = new Point(a, b + d); |
618 | - | bar.BottomLocation.Left = new Point(a, b + d); |
618 | + | |
619 | - | bar.BottomLocation.Right = new Point(a, b + d); |
619 | + | LinearGradientBrush obBrush = null; |
620 | Rectangle obRect = new Rectangle(a, b, c, d); | |
621 | - | LinearGradientBrush obBrush = null; |
621 | + | |
622 | - | Rectangle obRect = new Rectangle(a, b, c, d); |
622 | + | if (bar.StartValue != null & endValue != null) |
623 | { | |
624 | - | if (bar.StartValue != null & endValue != null) |
624 | + | |
625 | if ((index >= scrollPos & index < barsViewable + scrollPos) | ignoreScrollAndMousePosition == true) | |
626 | { | |
627 | - | if ((index >= scrollPos & index < barsViewable + scrollPos) | ignoreScrollAndMousePosition == true) |
627 | + | // Makes the bar gradient |
628 | ||
629 | - | // Makes the bar gradient |
629 | + | obBrush = new LinearGradientBrush(obRect, color, Color.Gray, LinearGradientMode.Vertical); |
630 | ||
631 | - | obBrush = new LinearGradientBrush(obRect, color, Color.Gray, LinearGradientMode.Vertical); |
631 | + | // Draws the bar |
632 | ||
633 | - | // Draws the bar |
633 | + | grfx.DrawRectangle(Pens.Black, obRect); |
634 | grfx.FillRectangle(obBrush, obRect); | |
635 | - | grfx.DrawRectangle(Pens.Black, obRect); |
635 | + | |
636 | - | grfx.FillRectangle(obBrush, obRect); |
636 | + | // Draws the rowtext |
637 | ||
638 | - | // Draws the rowtext |
638 | + | grfx.DrawString(bar.Text, rowTextFont, Brushes.Black, 0, barStartTop + (barHeight * (index - scrollPos)) + (barSpace * (index - scrollPos))); |
639 | ||
640 | - | grfx.DrawString(bar.Text, rowTextFont, Brushes.Black, 0, barStartTop + (barHeight * (index - scrollPos)) + (barSpace * (index - scrollPos))); |
640 | + | obBrush = null; |
641 | //obRect = null; | |
642 | - | obBrush = null; |
642 | + | //obRect.TryDispose(); |
643 | - | //obRect = null; |
643 | + | obBrush = null; |
644 | - | //obRect.TryDispose(); |
644 | + | |
645 | - | obBrush = null; |
645 | + | |
646 | ||
647 | //color = null; | |
648 | //color.TryDispose(); | |
649 | - | //color = null; |
649 | + | |
650 | - | //color.TryDispose(); |
650 | + | } |
651 | ||
652 | /// <summary> | |
653 | /// Draws the vertical lines | |
654 | /// </summary> | |
655 | - | /// Draws the vertical lines |
655 | + | /// <param name="grfx"></param> |
656 | /// <remarks></remarks> | |
657 | - | /// <param name="grfx"></param> |
657 | + | |
658 | public void DrawNetVertical(Graphics grfx) | |
659 | { | |
660 | - | public void DrawNetVertical(Graphics grfx) |
660 | + | if (shownHeaderList == null) |
661 | return; | |
662 | - | if (shownHeaderList == null) |
662 | + | if (shownHeaderList.Count == 0) |
663 | return; | |
664 | - | if (shownHeaderList.Count == 0) |
664 | + | |
665 | int index = 0; | |
666 | int availableWidth = this.Width - 10 - barStartLeft - barStartRight; | |
667 | Header lastHeader = null; | |
668 | - | int availableWidth = this.Width - 10 - barStartLeft - barStartRight; |
668 | + | |
669 | - | Header lastHeader = null; |
669 | + | foreach (Header header in shownHeaderList) |
670 | { | |
671 | - | foreach (Header header in shownHeaderList) |
671 | + | int headerLocationY = 0; |
672 | ||
673 | - | int headerLocationY = 0; |
673 | + | if (lastHeader == null) |
674 | { | |
675 | - | if (lastHeader == null) |
675 | + | headerLocationY = 0; |
676 | } | |
677 | - | headerLocationY = 0; |
677 | + | else if (header.Time.Hour < lastHeader.Time.Hour) |
678 | { | |
679 | - | else if (header.Time.Hour < lastHeader.Time.Hour) |
679 | + | headerLocationY = 0; |
680 | } | |
681 | - | headerLocationY = 0; |
681 | + | |
682 | { | |
683 | headerLocationY = headerTimeStartTop; | |
684 | } | |
685 | - | headerLocationY = headerTimeStartTop; |
685 | + | |
686 | grfx.DrawLine(Pens.Bisque, barStartLeft + (index * widthPerItem), headerLocationY, barStartLeft + (index * widthPerItem), lastLineStop); | |
687 | index += 1; | |
688 | - | grfx.DrawLine(Pens.Bisque, barStartLeft + (index * widthPerItem), headerLocationY, barStartLeft + (index * widthPerItem), lastLineStop); |
688 | + | |
689 | lastHeader = header; | |
690 | } | |
691 | - | lastHeader = header; |
691 | + | |
692 | grfx.DrawLine(lineColor, barStartLeft + (index * widthPerItem), headerTimeStartTop, barStartLeft + (index * widthPerItem), lastLineStop); | |
693 | } | |
694 | - | grfx.DrawLine(lineColor, barStartLeft + (index * widthPerItem), headerTimeStartTop, barStartLeft + (index * widthPerItem), lastLineStop); |
694 | + | |
695 | /// <summary> | |
696 | /// Draws the horizontal lines | |
697 | /// </summary> | |
698 | - | /// Draws the horizontal lines |
698 | + | /// <param name="grfx"></param> |
699 | /// <remarks></remarks> | |
700 | - | /// <param name="grfx"></param> |
700 | + | |
701 | public void DrawNetHorizontal(Graphics grfx) | |
702 | { | |
703 | - | public void DrawNetHorizontal(Graphics grfx) |
703 | + | if (shownHeaderList == null) |
704 | return; | |
705 | - | if (shownHeaderList == null) |
705 | + | if (shownHeaderList.Count == 0) |
706 | return; | |
707 | - | if (shownHeaderList.Count == 0) |
707 | + | |
708 | int index = 0; | |
709 | int width = (widthPerItem * shownHeaderList.Count) + barStartLeft; | |
710 | ||
711 | - | int width = (widthPerItem * shownHeaderList.Count) + barStartLeft; |
711 | + | // Last used index. Hopefully nobody will make a row named QQQ :o) |
712 | for (index = 0; index <= GetIndexChartBar("QQQQQQ"); index++) | |
713 | - | // Last used index. Hopefully nobody will make a row named QQQ :o) |
713 | + | |
714 | - | for (index = 0; index <= GetIndexChartBar("QQQQQQ"); index++) |
714 | + | |
715 | { | |
716 | - | foreach (ChartBarDate bar in bars) |
716 | + | grfx.DrawLine(lineColor, 0, barStartTop + (barHeight * index) + (barSpace * index), width, barStartTop + (barHeight * index) + (barSpace * index)); |
717 | } | |
718 | - | grfx.DrawLine(lineColor, 0, barStartTop + (barHeight * index) + (barSpace * index), width, barStartTop + (barHeight * index) + (barSpace * index)); |
718 | + | |
719 | ||
720 | lastLineStop = barStartTop + (barHeight * (index - 1)) + (barSpace * (index - 1)); | |
721 | } | |
722 | - | lastLineStop = barStartTop + (barHeight * (index - 1)) + (barSpace * (index - 1)); |
722 | + | |
723 | // This is the position (in pixels, from top) of the last line. Used for drawing lines | |
724 | ||
725 | - | // This is the position (in pixels, from top) of the last line. Used for drawing lines |
725 | + | |
726 | private int lastLineStop = 0; | |
727 | #endregion | |
728 | - | private int lastLineStop = 0; |
728 | + | |
729 | - | #endregion |
729 | + | #region "Header list" |
730 | ||
731 | - | #region "Header list" |
731 | + | |
732 | /// Gets the full header list, consisting of hours between the two dates set | |
733 | /// </summary> | |
734 | - | /// Gets the full header list, consisting of hours between the two dates set |
734 | + | /// <returns></returns> |
735 | /// <remarks></remarks> | |
736 | ||
737 | private List<Header> GetFullHeaderList() | |
738 | { | |
739 | - | private List<Header> GetFullHeaderList() |
739 | + | List<Header> result = new List<Header>(); |
740 | System.DateTime newFromTime = new System.DateTime(FromDate.Year, FromDate.Month, FromDate.Day); | |
741 | - | List<Header> result = new List<Header>(); |
741 | + | string item = null; |
742 | - | System.DateTime newFromTime = new System.DateTime(FromDate.Year, FromDate.Month, FromDate.Day); |
742 | + | |
743 | - | string item = null; |
743 | + | TimeSpan interval = ToDate - FromDate; |
744 | ||
745 | - | TimeSpan interval = ToDate - FromDate; |
745 | + | if (interval.TotalDays < 1) |
746 | { | |
747 | - | if (interval.TotalDays < 1) |
747 | + | var _with1 = newFromTime; |
748 | newFromTime = _with1.AddHours(FromDate.Hour); | |
749 | - | var _with1 = newFromTime; |
749 | + | |
750 | - | newFromTime = _with1.AddHours(FromDate.Hour); |
750 | + | if (headerFromDate.Minute < 59 & headerFromDate.Minute > 29) |
751 | { | |
752 | - | if (headerFromDate.Minute < 59 & headerFromDate.Minute > 29) |
752 | + | newFromTime = _with1.AddMinutes(30); |
753 | } | |
754 | - | newFromTime = _with1.AddMinutes(30); |
754 | + | |
755 | { | |
756 | newFromTime = _with1.AddMinutes(0); | |
757 | } | |
758 | - | newFromTime = _with1.AddMinutes(0); |
758 | + | |
759 | while (newFromTime <= ToDate) | |
760 | { | |
761 | - | while (newFromTime <= ToDate) |
761 | + | item = newFromTime.Hour + ":"; |
762 | ||
763 | - | item = newFromTime.Hour + ":"; |
763 | + | if (newFromTime.Minute < 10) |
764 | { | |
765 | - | if (newFromTime.Minute < 10) |
765 | + | item += "0" + newFromTime.Minute; |
766 | } | |
767 | - | item += "0" + newFromTime.Minute; |
767 | + | |
768 | { | |
769 | - | else |
769 | + | item += "" + newFromTime.Minute; |
770 | } | |
771 | - | item += "" + newFromTime.Minute; |
771 | + | |
772 | Header header = new Header(); | |
773 | ||
774 | - | Header header = new Header(); |
774 | + | header.HeaderText = item; |
775 | header.HeaderTextInsteadOfTime = ""; | |
776 | - | header.HeaderText = item; |
776 | + | header.Time = new System.DateTime(newFromTime.Year, newFromTime.Month, newFromTime.Day, newFromTime.Hour, newFromTime.Minute, 0); |
777 | - | header.HeaderTextInsteadOfTime = ""; |
777 | + | result.Add(header); |
778 | - | header.Time = new System.DateTime(newFromTime.Year, newFromTime.Month, newFromTime.Day, newFromTime.Hour, newFromTime.Minute, 0); |
778 | + | |
779 | - | result.Add(header); |
779 | + | newFromTime = newFromTime.AddMinutes(5); |
780 | // The minimum interval of time between the headers | |
781 | - | newFromTime = newFromTime.AddMinutes(5); |
781 | + | |
782 | - | // The minimum interval of time between the headers |
782 | + | |
783 | else if (interval.TotalDays < 60) | |
784 | { | |
785 | - | else if (interval.TotalDays < 60) |
785 | + | while (newFromTime <= ToDate) |
786 | { | |
787 | - | while (newFromTime <= ToDate) |
787 | + | Header header = new Header(); |
788 | ||
789 | - | Header header = new Header(); |
789 | + | header.HeaderText = ""; |
790 | header.HeaderTextInsteadOfTime = ""; | |
791 | - | header.HeaderText = ""; |
791 | + | header.Time = new System.DateTime(newFromTime.Year, newFromTime.Month, newFromTime.Day, 0, 0, 0); |
792 | - | header.HeaderTextInsteadOfTime = ""; |
792 | + | result.Add(header); |
793 | - | header.Time = new System.DateTime(newFromTime.Year, newFromTime.Month, newFromTime.Day, 0, 0, 0); |
793 | + | |
794 | - | result.Add(header); |
794 | + | newFromTime = newFromTime.AddDays(1); |
795 | // The minimum interval of time between the headers | |
796 | - | newFromTime = newFromTime.AddDays(1); |
796 | + | |
797 | - | // The minimum interval of time between the headers |
797 | + | |
798 | else | |
799 | { | |
800 | while (newFromTime <= ToDate) | |
801 | { | |
802 | - | while (newFromTime <= ToDate) |
802 | + | Header header = new Header(); |
803 | ||
804 | - | Header header = new Header(); |
804 | + | header.HeaderText = ""; |
805 | header.Time = new System.DateTime(newFromTime.Year, newFromTime.Month, newFromTime.Day, 0, 0, 0); | |
806 | - | header.HeaderText = ""; |
806 | + | header.HeaderTextInsteadOfTime = newFromTime.ToString("MMM"); |
807 | - | header.Time = new System.DateTime(newFromTime.Year, newFromTime.Month, newFromTime.Day, 0, 0, 0); |
807 | + | result.Add(header); |
808 | - | header.HeaderTextInsteadOfTime = newFromTime.ToString("MMM"); |
808 | + | |
809 | - | result.Add(header); |
809 | + | newFromTime = newFromTime.AddMonths(1); |
810 | // The minimum interval of time between the headers | |
811 | - | newFromTime = newFromTime.AddMonths(1); |
811 | + | |
812 | - | // The minimum interval of time between the headers |
812 | + | |
813 | ||
814 | return result; | |
815 | } | |
816 | - | return result; |
816 | + | |
817 | #endregion | |
818 | ||
819 | - | #endregion |
819 | + | #region "Mouse Move" |
820 | ||
821 | - | #region "Mouse Move" |
821 | + | |
822 | /// Finds the current row and column based on mouse position | |
823 | /// </summary> | |
824 | - | /// Finds the current row and column based on mouse position |
824 | + | /// <param name="sender"></param> |
825 | /// <param name="e"></param> | |
826 | - | /// <param name="sender"></param> |
826 | + | /// <remarks></remarks> |
827 | - | /// <param name="e"></param> |
827 | + | |
828 | private void GanttChart_MouseMove(System.Object sender, System.Windows.Forms.MouseEventArgs e) | |
829 | { | |
830 | - | private void GanttChart_MouseMove(System.Object sender, System.Windows.Forms.MouseEventArgs e) |
830 | + | if (shownHeaderList == null) |
831 | return; | |
832 | - | if (shownHeaderList == null) |
832 | + | if (shownHeaderList.Count == 0) |
833 | return; | |
834 | - | if (shownHeaderList.Count == 0) |
834 | + | |
835 | if (e.Button != System.Windows.Forms.MouseButtons.Left) | |
836 | { | |
837 | - | if (e.Button != System.Windows.Forms.MouseButtons.Left) |
837 | + | |
838 | ||
839 | - | mouseHoverPart = MouseOverPart.Empty; |
839 | + | // If bar has changed manually, but left mouse button is no longer pressed the BarChanged event will be raised |
840 | ||
841 | - | // If bar has changed manually, but left mouse button is no longer pressed the BarChanged event will be raised |
841 | + | |
842 | { | |
843 | - | if (AllowManualEditBar == true) |
843 | + | if (barIsChanging >= 0) |
844 | { | |
845 | - | if (barIsChanging >= 0) |
845 | + | if (BarChanged != null) |
846 | { | |
847 | - | if (BarChanged != null) |
847 | + | BarChanged(this, bars[barIsChanging].Value); |
848 | } | |
849 | - | BarChanged(this, bars[barIsChanging].Value); |
849 | + | barIsChanging = -1; |
850 | } | |
851 | - | barIsChanging = -1; |
851 | + | |
852 | } | |
853 | else if (e.Button == System.Windows.Forms.MouseButtons.Left) | |
854 | { | |
855 | if (AllowManualEditBar == true) | |
856 | - | mouseHoverBarIndex = -1; |
856 | + | |
857 | if (barIsChanging >= 0) | |
858 | { | |
859 | if (BarChanging != null) | |
860 | { | |
861 | BarChanging(this, bars[barIsChanging].Value); | |
862 | - | // Finds pixels per minute |
862 | + | |
863 | } | |
864 | - | TimeSpan timeBetween = shownHeaderList[1].Time - shownHeaderList[0].Time; |
864 | + | |
865 | - | int minutesBetween = (timeBetween.Days * 1440) + (timeBetween.Hours * 60) + timeBetween.Minutes; |
865 | + | |
866 | - | dynamic widthBetween = (shownHeaderList[1].StartLocation - shownHeaderList[0].StartLocation); |
866 | + | |
867 | - | decimal perMinute = widthBetween / minutesBetween; |
867 | + | mouseHoverBarIndex = -1; |
868 | ||
869 | - | // Finds the time at mousepointer |
869 | + | Point LocalMousePosition = default(Point); |
870 | ||
871 | - | int minutesAtCursor = 0; |
871 | + | LocalMousePosition = this.PointToClient(Cursor.Position); |
872 | ||
873 | - | if (LocalMousePosition.X > barStartLeft && perMinute > 0) |
873 | + | // Finds pixels per minute |
874 | ||
875 | - | minutesAtCursor = Convert.ToInt32((LocalMousePosition.X - barStartLeft) / perMinute); |
875 | + | TimeSpan timeBetween = shownHeaderList[1].Time - shownHeaderList[0].Time; |
876 | - | _mouseOverColumnValue = FromDate.AddMinutes(minutesAtCursor); |
876 | + | int minutesBetween = (timeBetween.Days * 1440) + (timeBetween.Hours * 60) + timeBetween.Minutes; |
877 | dynamic widthBetween = (shownHeaderList[1].StartLocation - shownHeaderList[0].StartLocation); | |
878 | decimal perMinute = Convert.ToDecimal(widthBetween) / Convert.ToDecimal(minutesBetween); | |
879 | ||
880 | - | //_mouseOverColumnValue.TryDispose(); |
880 | + | // Finds the time at mousepointer |
881 | ||
882 | int minutesAtCursor = 0; | |
883 | - | // Finds the row at mousepointer |
883 | + | |
884 | if (LocalMousePosition.X > barStartLeft && perMinute > 0) | |
885 | - | string rowText = ""; |
885 | + | |
886 | - | object rowValue = null; |
886 | + | minutesAtCursor = Convert.ToInt32((LocalMousePosition.X - barStartLeft) / perMinute); |
887 | - | string columnText = ""; |
887 | + | _mouseOverColumnValue = FromDate.AddMinutes(minutesAtCursor); |
888 | } | |
889 | - | // Tests to see if the mouse pointer is hovering above the scrollbar |
889 | + | else |
890 | { | |
891 | - | bool scrollBarStatusChanged = false; |
891 | + | //_mouseOverColumnValue.TryDispose(); |
892 | } | |
893 | - | // Tests to see if the mouse is hovering over the scroll-area bottom-arrow |
893 | + | |
894 | // Finds the row at mousepointer | |
895 | - | if (LocalMousePosition.X > BottomPart.Left & LocalMousePosition.Y < BottomPart.Right & LocalMousePosition.Y < BottomPart.Bottom & LocalMousePosition.Y > BottomPart.Top) |
895 | + | |
896 | string rowText = ""; | |
897 | - | if (mouseOverBottomPart == false) |
897 | + | object rowValue = null; |
898 | string columnText = ""; | |
899 | - | scrollBarStatusChanged = true; |
899 | + | |
900 | // Tests to see if the mouse pointer is hovering above the scrollbar | |
901 | ||
902 | - | mouseOverBottomPart = true; |
902 | + | bool scrollBarStatusChanged = false; |
903 | ||
904 | // Tests to see if the mouse is hovering over the scroll-area bottom-arrow | |
905 | ||
906 | - | if (mouseOverBottomPart == false) |
906 | + | if (LocalMousePosition.X > BottomPart.Left & LocalMousePosition.Y < BottomPart.Right & LocalMousePosition.Y < BottomPart.Bottom & LocalMousePosition.Y > BottomPart.Top) |
907 | { | |
908 | - | scrollBarStatusChanged = true; |
908 | + | if (mouseOverBottomPart == false) |
909 | { | |
910 | scrollBarStatusChanged = true; | |
911 | - | mouseOverBottomPart = false; |
911 | + | |
912 | ||
913 | mouseOverBottomPart = true; | |
914 | - | // Tests to see if the mouse is hovering over the scroll-area top-arrow |
914 | + | |
915 | else | |
916 | - | if (LocalMousePosition.X > topPart.Left & LocalMousePosition.Y < topPart.Right & LocalMousePosition.Y < topPart.Bottom & LocalMousePosition.Y > topPart.Top) |
916 | + | |
917 | if (mouseOverBottomPart == false) | |
918 | - | if (mouseOverTopPart == false) |
918 | + | |
919 | scrollBarStatusChanged = true; | |
920 | - | scrollBarStatusChanged = true; |
920 | + | |
921 | ||
922 | mouseOverBottomPart = false; | |
923 | - | mouseOverTopPart = true; |
923 | + | |
924 | ||
925 | // Tests to see if the mouse is hovering over the scroll-area top-arrow | |
926 | ||
927 | - | if (mouseOverTopPart == false) |
927 | + | if (LocalMousePosition.X > topPart.Left & LocalMousePosition.Y < topPart.Right & LocalMousePosition.Y < topPart.Bottom & LocalMousePosition.Y > topPart.Top) |
928 | { | |
929 | - | scrollBarStatusChanged = true; |
929 | + | if (mouseOverTopPart == false) |
930 | { | |
931 | scrollBarStatusChanged = true; | |
932 | - | mouseOverTopPart = false; |
932 | + | |
933 | ||
934 | mouseOverTopPart = true; | |
935 | - | // Tests to see if the mouse is hovering over the scroll |
935 | + | |
936 | else | |
937 | - | if (LocalMousePosition.X > scroll.Left & LocalMousePosition.Y < scroll.Right & LocalMousePosition.Y < scroll.Bottom & LocalMousePosition.Y > scroll.Top) |
937 | + | |
938 | if (mouseOverTopPart == false) | |
939 | - | if (mouseOverScrollBar == false) |
939 | + | |
940 | scrollBarStatusChanged = true; | |
941 | - | scrollBarStatusChanged = true; |
941 | + | |
942 | ||
943 | mouseOverTopPart = false; | |
944 | - | mouseOverScrollBar = true; |
944 | + | |
945 | ||
946 | // Tests to see if the mouse is hovering over the scroll | |
947 | ||
948 | if (LocalMousePosition.X > scroll.Left & LocalMousePosition.Y < scroll.Right & LocalMousePosition.Y < scroll.Bottom & LocalMousePosition.Y > scroll.Top) | |
949 | - | if (mouseOverScrollBar == false) |
949 | + | |
950 | if (mouseOverScrollBar == false) | |
951 | - | scrollBarStatusChanged = true; |
951 | + | |
952 | scrollBarStatusChanged = true; | |
953 | } | |
954 | - | mouseOverScrollBar = false; |
954 | + | |
955 | - | mouseOverScrollBarArea = false; |
955 | + | mouseOverScrollBar = true; |
956 | mouseOverScrollBarArea = true; | |
957 | } | |
958 | - | // If the mouse is not above the scroll, test if it's over the scroll area (no need to test if it's not above the scroll) |
958 | + | else |
959 | { | |
960 | - | if (mouseOverScrollBarArea == false) |
960 | + | if (mouseOverScrollBar == false) |
961 | { | |
962 | - | if (LocalMousePosition.X > scrollBarArea.Left & LocalMousePosition.Y < scrollBarArea.Right & LocalMousePosition.Y < scrollBarArea.Bottom & LocalMousePosition.Y > scrollBarArea.Top) |
962 | + | scrollBarStatusChanged = true; |
963 | } | |
964 | - | mouseOverScrollBarArea = true; |
964 | + | |
965 | mouseOverScrollBar = false; | |
966 | mouseOverScrollBarArea = false; | |
967 | } | |
968 | ||
969 | - | // Tests to see if the mouse pointer is hovering above a bar |
969 | + | // If the mouse is not above the scroll, test if it's over the scroll area (no need to test if it's not above the scroll) |
970 | ||
971 | if (mouseOverScrollBarArea == false) | |
972 | { | |
973 | if (LocalMousePosition.X > scrollBarArea.Left & LocalMousePosition.Y < scrollBarArea.Right & LocalMousePosition.Y < scrollBarArea.Bottom & LocalMousePosition.Y > scrollBarArea.Top) | |
974 | { | |
975 | mouseOverScrollBarArea = true; | |
976 | - | // If the bar is set to be hidden from mouse move, the current bar will be ignored |
976 | + | |
977 | } | |
978 | - | if (bar.HideFromMouseMove == false) |
978 | + | |
979 | ||
980 | - | if (bar.EndValue == null) |
980 | + | // Tests to see if the mouse pointer is hovering above a bar |
981 | ||
982 | - | bar.EndValue = System.DateTime.Now; |
982 | + | int index = 0; |
983 | ||
984 | ||
985 | - | // Mouse pointer needs to be inside the X and Y positions of the bar |
985 | + | foreach (ChartBarDate bar in bars) |
986 | { | |
987 | - | if (LocalMousePosition.Y > bar.TopLocation.Left.Y & LocalMousePosition.Y < bar.BottomLocation.Left.Y) |
987 | + | // If the bar is set to be hidden from mouse move, the current bar will be ignored |
988 | ||
989 | if (bar.HideFromMouseMove == false) | |
990 | - | if (LocalMousePosition.X > bar.TopLocation.Left.X & LocalMousePosition.X < bar.TopLocation.Right.X) |
990 | + | |
991 | if (bar.EndValue == null) | |
992 | - | // If the current bar is the one where the mouse is above, the rowText and rowValue needs to be set correctly |
992 | + | |
993 | bar.EndValue = System.DateTime.Now; | |
994 | - | rowText = bar.Text; |
994 | + | |
995 | - | rowValue = bar.Value; |
995 | + | |
996 | // Mouse pointer needs to be inside the X and Y positions of the bar | |
997 | ||
998 | - | if (mouseHoverPart != MouseOverPart.BarLeftSide & mouseHoverPart != MouseOverPart.BarRightSide) |
998 | + | if (LocalMousePosition.Y > bar.TopLocation.Left.Y & LocalMousePosition.Y < bar.BottomLocation.Left.Y) |
999 | - | { |
999 | + | |
1000 | - | mouseHoverPart = MouseOverPart.Bar; |
1000 | + | |
1001 | - | } |
1001 | + | if (LocalMousePosition.X > bar.TopLocation.Left.X & LocalMousePosition.X < bar.TopLocation.Right.X) |
1002 | { | |
1003 | // If the current bar is the one where the mouse is above, the rowText and rowValue needs to be set correctly | |
1004 | - | // If mouse pointer is near the edges of the bar it will open up for editing the bar |
1004 | + | |
1005 | rowText = bar.Text; | |
1006 | - | if (AllowManualEditBar == true) |
1006 | + | rowValue = bar.Value; |
1007 | mouseHoverBarIndex = index; | |
1008 | - | int areaSize = 5; |
1008 | + | |
1009 | if (mouseHoverPart != MouseOverPart.BarLeftSide & mouseHoverPart != MouseOverPart.BarRightSide) | |
1010 | - | if (e.Button == System.Windows.Forms.MouseButtons.Left) |
1010 | + | |
1011 | - | { |
1011 | + | mouseHoverPart = MouseOverPart.Bar; |
1012 | - | areaSize = 50; |
1012 | + | |
1013 | - | } |
1013 | + | |
1014 | ||
1015 | - | if (LocalMousePosition.X > bar.TopLocation.Left.X - areaSize & LocalMousePosition.X < bar.TopLocation.Left.X + areaSize & mouseHoverPart != MouseOverPart.BarRightSide) |
1015 | + | // If mouse pointer is near the edges of the bar it will open up for editing the bar |
1016 | - | { |
1016 | + | |
1017 | - | this.Cursor = Cursors.VSplit; |
1017 | + | if (AllowManualEditBar == true) |
1018 | - | mouseHoverPart = MouseOverPart.BarLeftSide; |
1018 | + | |
1019 | - | mouseHoverBarIndex = index; |
1019 | + | int areaSize = 5; |
1020 | - | } |
1020 | + | |
1021 | - | else if (LocalMousePosition.X > bar.TopLocation.Right.X - areaSize & LocalMousePosition.X < bar.TopLocation.Right.X + areaSize & mouseHoverPart != MouseOverPart.BarLeftSide) |
1021 | + | if (e.Button == System.Windows.Forms.MouseButtons.Left) |
1022 | - | { |
1022 | + | |
1023 | - | this.Cursor = Cursors.VSplit; |
1023 | + | areaSize = 50; |
1024 | - | mouseHoverPart = MouseOverPart.BarRightSide; |
1024 | + | |
1025 | - | mouseHoverBarIndex = index; |
1025 | + | |
1026 | - | } |
1026 | + | if (LocalMousePosition.X > bar.TopLocation.Left.X - areaSize & LocalMousePosition.X < bar.TopLocation.Left.X + areaSize & mouseHoverPart != MouseOverPart.BarRightSide) |
1027 | - | else |
1027 | + | |
1028 | - | { |
1028 | + | this.Cursor = Cursors.VSplit; |
1029 | - | this.Cursor = Cursors.Default; |
1029 | + | mouseHoverPart = MouseOverPart.BarLeftSide; |
1030 | - | } |
1030 | + | |
1031 | } | |
1032 | else if (LocalMousePosition.X > bar.TopLocation.Right.X - areaSize & LocalMousePosition.X < bar.TopLocation.Right.X + areaSize & mouseHoverPart != MouseOverPart.BarLeftSide) | |
1033 | { | |
1034 | this.Cursor = Cursors.VSplit; | |
1035 | mouseHoverPart = MouseOverPart.BarRightSide; | |
1036 | mouseHoverBarIndex = index; | |
1037 | } | |
1038 | - | // Sets the mouseover row value and text |
1038 | + | else |
1039 | { | |
1040 | - | _mouseOverRowText = rowText; |
1040 | + | this.Cursor = Cursors.Default; |
1041 | - | _mouseOverRowValue = rowValue; |
1041 | + | |
1042 | } | |
1043 | - | if (e.Button == System.Windows.Forms.MouseButtons.Left) |
1043 | + | |
1044 | } | |
1045 | - | if (MouseDragged != null) |
1045 | + | |
1046 | index += 1; | |
1047 | - | MouseDragged(sender, e); |
1047 | + | |
1048 | ||
1049 | // Sets the mouseover row value and text | |
1050 | ||
1051 | _mouseOverRowText = rowText; | |
1052 | _mouseOverRowValue = rowValue; | |
1053 | - | // A simple test to see if the mousemovement has caused any changes to how it should be displayed |
1053 | + | |
1054 | - | // It only redraws if mouse moves from a bar to blank area or from blank area to a bar |
1054 | + | if (e.Button == System.Windows.Forms.MouseButtons.Left) |
1055 | - | // This increases performance compared to having a redraw every time a mouse moves |
1055 | + | |
1056 | if (MouseDragged != null) | |
1057 | - | if ((_mouseOverRowValue == null & (rowValue != null)) | ((_mouseOverRowValue != null) & rowValue == null) | scrollBarStatusChanged == true) |
1057 | + | |
1058 | MouseDragged(sender, e); | |
1059 | } | |
1060 | ||
1061 | } | |
1062 | else | |
1063 | { | |
1064 | // A simple test to see if the mousemovement has caused any changes to how it should be displayed | |
1065 | - | /// Mouse leave event |
1065 | + | // It only redraws if mouse moves from a bar to blank area or from blank area to a bar |
1066 | // This increases performance compared to having a redraw every time a mouse moves | |
1067 | - | /// <param name="sender"></param> |
1067 | + | |
1068 | - | /// <param name="e"></param> |
1068 | + | if ((_mouseOverRowValue == null & (rowValue != null)) | ((_mouseOverRowValue != null) & rowValue == null) | scrollBarStatusChanged == true) |
1069 | { | |
1070 | PaintChart(); | |
1071 | - | private void GanttChart_MouseLeave(System.Object sender, System.EventArgs e) |
1071 | + | |
1072 | } | |
1073 | - | _mouseOverRowText = null; |
1073 | + | } |
1074 | - | _mouseOverRowValue = null; |
1074 | + | |
1075 | /// <summary> | |
1076 | /// Mouse leave event | |
1077 | - | PaintChart(); |
1077 | + | |
1078 | /// <param name="sender"></param> | |
1079 | /// <param name="e"></param> | |
1080 | /// <remarks></remarks> | |
1081 | - | /// Mouse drag event |
1081 | + | |
1082 | private void GanttChart_MouseLeave(System.Object sender, System.EventArgs e) | |
1083 | - | /// <param name="sender"></param> |
1083 | + | |
1084 | - | /// <param name="e"></param> |
1084 | + | _mouseOverRowText = null; |
1085 | _mouseOverRowValue = null; | |
1086 | mouseHoverPart = MouseOverPart.Empty; | |
1087 | - | public void GanttChart_MouseDragged(object sender, System.Windows.Forms.MouseEventArgs e) |
1087 | + | |
1088 | PaintChart(); | |
1089 | - | if (mouseOverScrollBarArea == true) |
1089 | + | } |
1090 | ||
1091 | - | ScrollPositionY = e.Location.Y; |
1091 | + | |
1092 | /// Mouse drag event | |
1093 | /// </summary> | |
1094 | /// <param name="sender"></param> | |
1095 | /// <param name="e"></param> | |
1096 | - | if (mouseHoverBarIndex > -1) |
1096 | + | /// <remarks></remarks> |
1097 | ||
1098 | - | if (mouseHoverPart == MouseOverPart.BarLeftSide) |
1098 | + | public void GanttChart_MouseDragged(object sender, System.Windows.Forms.MouseEventArgs e) |
1099 | { | |
1100 | - | barIsChanging = mouseHoverBarIndex; |
1100 | + | if (mouseOverScrollBarArea == true) |
1101 | - | bars[mouseHoverBarIndex].StartValue = _mouseOverColumnValue; |
1101 | + | |
1102 | ScrollPositionY = e.Location.Y; | |
1103 | } | |
1104 | - | else if (mouseHoverPart == MouseOverPart.BarRightSide) |
1104 | + | |
1105 | if (AllowManualEditBar == true) | |
1106 | - | barIsChanging = mouseHoverBarIndex; |
1106 | + | |
1107 | - | bars[mouseHoverBarIndex].EndValue = _mouseOverColumnValue; |
1107 | + | if (mouseHoverBarIndex > -1) |
1108 | { | |
1109 | if (mouseHoverPart == MouseOverPart.BarLeftSide) | |
1110 | { | |
1111 | barIsChanging = mouseHoverBarIndex; | |
1112 | bars[mouseHoverBarIndex].StartValue = _mouseOverColumnValue; | |
1113 | PaintChart(); | |
1114 | } | |
1115 | - | #endregion |
1115 | + | else if (mouseHoverPart == MouseOverPart.BarRightSide) |
1116 | { | |
1117 | - | #region "ToolTipText" |
1117 | + | barIsChanging = mouseHoverBarIndex; |
1118 | bars[mouseHoverBarIndex].EndValue = _mouseOverColumnValue; | |
1119 | - | private List<string> _toolTipText = new List<string>(); |
1119 | + | |
1120 | } | |
1121 | - | private string _toolTipTextTitle = ""; |
1121 | + | |
1122 | } | |
1123 | - | private Point MyPoint = new Point(0, 0); |
1123 | + | } |
1124 | ||
1125 | - | /// The title to draw |
1125 | + | |
1126 | #endregion | |
1127 | ||
1128 | #region "ToolTipText" | |
1129 | ||
1130 | private List<string> _toolTipText = new List<string>(); | |
1131 | - | public string ToolTipTextTitle |
1131 | + | |
1132 | private string _toolTipTextTitle = ""; | |
1133 | - | get { return _toolTipTextTitle; } |
1133 | + | |
1134 | - | set { _toolTipTextTitle = value; } |
1134 | + | private Point MyPoint = new Point(0, 0); |
1135 | /// <summary> | |
1136 | /// The title to draw | |
1137 | /// </summary> | |
1138 | - | /// Gets or sets the ToolTipText lines |
1138 | + | /// <value></value> |
1139 | /// <returns></returns> | |
1140 | /// <remarks></remarks> | |
1141 | ||
1142 | - | /// <remarks>Don not use the add function directly on this, use ToolTipText = value</remarks> |
1142 | + | public string ToolTipTextTitle |
1143 | { | |
1144 | - | public List<string> ToolTipText |
1144 | + | get { return _toolTipTextTitle; } |
1145 | set { _toolTipTextTitle = value; } | |
1146 | - | get |
1146 | + | } |
1147 | ||
1148 | - | if (_toolTipText == null) |
1148 | + | |
1149 | - | _toolTipText = new List<string>(); |
1149 | + | /// Gets or sets the ToolTipText lines |
1150 | - | return _toolTipText; |
1150 | + | |
1151 | /// <value></value> | |
1152 | - | set |
1152 | + | /// <returns></returns> |
1153 | /// <remarks>Don not use the add function directly on this, use ToolTipText = value</remarks> | |
1154 | - | _toolTipText = value; |
1154 | + | |
1155 | public List<string> ToolTipText | |
1156 | - | Point LocalMousePosition = default(Point); |
1156 | + | |
1157 | get | |
1158 | - | LocalMousePosition = this.PointToClient(Cursor.Position); |
1158 | + | |
1159 | if (_toolTipText == null) | |
1160 | _toolTipText = new List<string>(); | |
1161 | - | if (LocalMousePosition == MyPoint) |
1161 | + | return _toolTipText; |
1162 | - | return; |
1162 | + | |
1163 | set | |
1164 | - | MyPoint = LocalMousePosition; |
1164 | + | |
1165 | _toolTipText = value; | |
1166 | - | ToolTip.SetToolTip(this, "."); |
1166 | + | |
1167 | Point LocalMousePosition = default(Point); | |
1168 | ||
1169 | LocalMousePosition = this.PointToClient(Cursor.Position); | |
1170 | ||
1171 | - | /// Draws the ToolTip window |
1171 | + | |
1172 | if (LocalMousePosition == MyPoint) | |
1173 | - | /// <param name="sender"></param> |
1173 | + | |
1174 | - | /// <param name="e"></param> |
1174 | + | |
1175 | MyPoint = LocalMousePosition; | |
1176 | ||
1177 | - | private void ToolTipText_Draw(System.Object sender, System.Windows.Forms.DrawToolTipEventArgs e) |
1177 | + | ToolTip.SetToolTip(this, "."); |
1178 | } | |
1179 | - | if (ToolTipText == null) |
1179 | + | } |
1180 | ||
1181 | - | ToolTipText = new List<string>(); |
1181 | + | |
1182 | /// Draws the ToolTip window | |
1183 | /// </summary> | |
1184 | /// <param name="sender"></param> | |
1185 | - | if (ToolTipText.Count == 0) |
1185 | + | /// <param name="e"></param> |
1186 | /// <remarks></remarks> | |
1187 | ||
1188 | private void ToolTipText_Draw(System.Object sender, System.Windows.Forms.DrawToolTipEventArgs e) | |
1189 | - | else if (ToolTipText[0].Length == 0) |
1189 | + | |
1190 | if (ToolTipText == null) | |
1191 | { | |
1192 | ToolTipText = new List<string>(); | |
1193 | return; | |
1194 | - | int x = 0; |
1194 | + | |
1195 | - | int y = 0; |
1195 | + | |
1196 | if (ToolTipText.Count == 0) | |
1197 | - | e.Graphics.FillRectangle(Brushes.AntiqueWhite, e.Bounds); |
1197 | + | |
1198 | - | e.DrawBorder(); |
1198 | + | return; |
1199 | } | |
1200 | - | int titleHeight = 14; |
1200 | + | else if (ToolTipText[0].Length == 0) |
1201 | - | int fontHeight = 12; |
1201 | + | |
1202 | return; | |
1203 | - | // Draws the line just below the title |
1203 | + | |
1204 | ||
1205 | - | e.Graphics.DrawLine(Pens.Black, 0, titleHeight, e.Bounds.Width, titleHeight); |
1205 | + | int x = 0; |
1206 | int y = 0; | |
1207 | - | int lines = 1; |
1207 | + | |
1208 | - | string text = ToolTipTextTitle; |
1208 | + | e.Graphics.FillRectangle(Brushes.AntiqueWhite, e.Bounds); |
1209 | e.DrawBorder(); | |
1210 | - | // Draws the title |
1210 | + | |
1211 | int titleHeight = 14; | |
1212 | - | using (Font font = new Font(e.Font, FontStyle.Bold)) |
1212 | + | int fontHeight = 12; |
1213 | ||
1214 | - | x = Convert.ToInt32((e.Bounds.Width - e.Graphics.MeasureString(text, font).Width) / 2); |
1214 | + | // Draws the line just below the title |
1215 | - | y = Convert.ToInt32((titleHeight - e.Graphics.MeasureString(text, font).Height) / 2); |
1215 | + | |
1216 | - | e.Graphics.DrawString(text, font, Brushes.Black, x, y); |
1216 | + | e.Graphics.DrawLine(Pens.Black, 0, titleHeight, e.Bounds.Width, titleHeight); |
1217 | ||
1218 | int lines = 1; | |
1219 | - | // Draws the lines |
1219 | + | string text = ToolTipTextTitle; |
1220 | - | for (int i = 0; i < ToolTipText.Count; i++) |
1220 | + | |
1221 | // Draws the title | |
1222 | - | Font font = new Font(e.Font, FontStyle.Regular); |
1222 | + | |
1223 | using (Font font = new Font(e.Font, FontStyle.Bold)) | |
1224 | - | if (ToolTipText[i].Contains("[b]")) |
1224 | + | |
1225 | x = Convert.ToInt32((e.Bounds.Width - e.Graphics.MeasureString(text, font).Width) / 2); | |
1226 | - | font = new Font(font.FontFamily, font.Size, FontStyle.Bold, font.Unit); |
1226 | + | y = Convert.ToInt32((titleHeight - e.Graphics.MeasureString(text, font).Height) / 2); |
1227 | - | ToolTipText[i] = ToolTipText[i].Replace("[b]", ""); |
1227 | + | e.Graphics.DrawString(text, font, Brushes.Black, x, y); |
1228 | } | |
1229 | ||
1230 | - | using (font) |
1230 | + | // Draws the lines |
1231 | for (int i = 0; i < ToolTipText.Count; i++) | |
1232 | - | x = 5; |
1232 | + | |
1233 | - | y = Convert.ToInt32((titleHeight - fontHeight - e.Graphics.MeasureString(ToolTipText[i], font).Height) / 2 + 10 + (lines * 14)); |
1233 | + | Font font = new Font(e.Font, FontStyle.Regular); |
1234 | - | e.Graphics.DrawString(ToolTipText[i], font, Brushes.Black, x, y); |
1234 | + | |
1235 | if (ToolTipText[i].Contains("[b]")) | |
1236 | { | |
1237 | - | lines += 1; |
1237 | + | font = new Font(font.FontFamily, font.Size, FontStyle.Bold, font.Unit); |
1238 | ToolTipText[i] = ToolTipText[i].Replace("[b]", ""); | |
1239 | - | //foreach (string str in ToolTipText) |
1239 | + | |
1240 | - | //{ |
1240 | + | |
1241 | - | // Font font = new Font(e.Font, FontStyle.Regular); |
1241 | + | using (font) |
1242 | { | |
1243 | - | // if (str.Contains("[b]")) |
1243 | + | x = 5; |
1244 | - | // { |
1244 | + | y = Convert.ToInt32((titleHeight - fontHeight - e.Graphics.MeasureString(ToolTipText[i], font).Height) / 2 + 10 + (lines * 14)); |
1245 | - | // font = new Font(font.FontFamily, font.Size, FontStyle.Bold, font.Unit); |
1245 | + | e.Graphics.DrawString(ToolTipText[i], font, Brushes.Black, x, y); |
1246 | - | // str = str.Replace("[b]", ""); |
1246 | + | |
1247 | - | // } |
1247 | + | |
1248 | lines += 1; | |
1249 | - | // using (font) |
1249 | + | |
1250 | - | // { |
1250 | + | //foreach (string str in ToolTipText) |
1251 | - | // x = 5; |
1251 | + | //{ |
1252 | - | // y = Convert.ToInt32((titleHeight - fontHeight - e.Graphics.MeasureString(str, font).Height) / 2 + 10 + (lines * 14)); |
1252 | + | // Font font = new Font(e.Font, FontStyle.Regular); |
1253 | - | // e.Graphics.DrawString(str, font, Brushes.Black, x, y); |
1253 | + | |
1254 | - | // } |
1254 | + | // if (str.Contains("[b]")) |
1255 | // { | |
1256 | - | // lines += 1; |
1256 | + | // font = new Font(font.FontFamily, font.Size, FontStyle.Bold, font.Unit); |
1257 | - | //} |
1257 | + | // str = str.Replace("[b]", ""); |
1258 | // } | |
1259 | ||
1260 | // using (font) | |
1261 | - | /// Automatically resizes the ToolTip window |
1261 | + | // { |
1262 | // x = 5; | |
1263 | - | /// <param name="sender"></param> |
1263 | + | // y = Convert.ToInt32((titleHeight - fontHeight - e.Graphics.MeasureString(str, font).Height) / 2 + 10 + (lines * 14)); |
1264 | - | /// <param name="e"></param> |
1264 | + | // e.Graphics.DrawString(str, font, Brushes.Black, x, y); |
1265 | // } | |
1266 | ||
1267 | - | private void ToolTipText_Popup(System.Object sender, System.Windows.Forms.PopupEventArgs e) |
1267 | + | // lines += 1; |
1268 | //} | |
1269 | - | if (ToolTipText == null) |
1269 | + | } |
1270 | ||
1271 | - | ToolTipText = new List<string>(); |
1271 | + | |
1272 | /// Automatically resizes the ToolTip window | |
1273 | /// </summary> | |
1274 | - | if (ToolTipText.Count == 0) |
1274 | + | /// <param name="sender"></param> |
1275 | /// <param name="e"></param> | |
1276 | - | e.ToolTipSize = new Size(0, 0); |
1276 | + | /// <remarks></remarks> |
1277 | ||
1278 | private void ToolTipText_Popup(System.Object sender, System.Windows.Forms.PopupEventArgs e) | |
1279 | - | else if (ToolTipText[0].Length == 0) |
1279 | + | |
1280 | if (ToolTipText == null) | |
1281 | - | e.ToolTipSize = new Size(0, 0); |
1281 | + | |
1282 | ToolTipText = new List<string>(); | |
1283 | } | |
1284 | ||
1285 | - | // resizes the ToolTip window |
1285 | + | if (ToolTipText.Count == 0) |
1286 | { | |
1287 | - | int height = 18 + (ToolTipText.Count * 15); |
1287 | + | e.ToolTipSize = new Size(0, 0); |
1288 | - | e.ToolTipSize = new Size(200, height); |
1288 | + | return; |
1289 | } | |
1290 | else if (ToolTipText[0].Length == 0) | |
1291 | - | #endregion |
1291 | + | |
1292 | e.ToolTipSize = new Size(0, 0); | |
1293 | - | #region "ChartBar" |
1293 | + | return; |
1294 | } | |
1295 | - | private class ChartBarDate |
1295 | + | |
1296 | // resizes the ToolTip window | |
1297 | ||
1298 | - | internal class Location |
1298 | + | int height = 18 + (ToolTipText.Count * 15); |
1299 | e.ToolTipSize = new Size(200, height); | |
1300 | } | |
1301 | - | private Point _right = new Point(0, 0); |
1301 | + | |
1302 | #endregion | |
1303 | - | private Point _left = new Point(0, 0); |
1303 | + | |
1304 | - | public Point Right |
1304 | + | #region "ChartBar" |
1305 | ||
1306 | - | get { return _right; } |
1306 | + | private class ChartBarDate |
1307 | - | set { _right = value; } |
1307 | + | |
1308 | ||
1309 | internal class Location | |
1310 | - | public Point Left |
1310 | + | |
1311 | ||
1312 | - | get { return _left; } |
1312 | + | private Point _right = new Point(0, 0); |
1313 | - | set { _left = value; } |
1313 | + | |
1314 | private Point _left = new Point(0, 0); | |
1315 | public Point Right | |
1316 | { | |
1317 | get { return _right; } | |
1318 | - | private System.DateTime _startValue; |
1318 | + | set { _right = value; } |
1319 | } | |
1320 | - | private System.DateTime _endValue; |
1320 | + | |
1321 | - | private Color _color; |
1321 | + | public Point Left |
1322 | { | |
1323 | - | private Color _hoverColor; |
1323 | + | get { return _left; } |
1324 | - | private string _text; |
1324 | + | set { _left = value; } |
1325 | } | |
1326 | - | private object _value; |
1326 | + | |
1327 | } | |
1328 | - | private int _rowIndex; |
1328 | + | |
1329 | - | private Location _topLocation = new Location(); |
1329 | + | private System.DateTime _startValue; |
1330 | ||
1331 | - | private Location _bottomLocation = new Location(); |
1331 | + | private System.DateTime _endValue; |
1332 | private Color _color; | |
1333 | - | private bool _hideFromMouseMove = false; |
1333 | + | |
1334 | - | public System.DateTime StartValue |
1334 | + | private Color _hoverColor; |
1335 | private string _text; | |
1336 | - | get { return _startValue; } |
1336 | + | |
1337 | - | set { _startValue = value; } |
1337 | + | private object _value; |
1338 | ||
1339 | private int _rowIndex; | |
1340 | - | public System.DateTime EndValue |
1340 | + | private Location _topLocation = new Location(); |
1341 | ||
1342 | - | get { return _endValue; } |
1342 | + | private Location _bottomLocation = new Location(); |
1343 | - | set { _endValue = value; } |
1343 | + | |
1344 | private bool _hideFromMouseMove = false; | |
1345 | public System.DateTime StartValue | |
1346 | - | public Color Color |
1346 | + | |
1347 | get { return _startValue; } | |
1348 | - | get { return _color; } |
1348 | + | set { _startValue = value; } |
1349 | - | set { _color = value; } |
1349 | + | |
1350 | ||
1351 | public System.DateTime EndValue | |
1352 | - | public Color HoverColor |
1352 | + | |
1353 | get { return _endValue; } | |
1354 | - | get { return _hoverColor; } |
1354 | + | set { _endValue = value; } |
1355 | - | set { _hoverColor = value; } |
1355 | + | |
1356 | ||
1357 | public Color Color | |
1358 | - | public string Text |
1358 | + | |
1359 | get { return _color; } | |
1360 | - | get { return _text; } |
1360 | + | set { _color = value; } |
1361 | - | set { _text = value; } |
1361 | + | |
1362 | ||
1363 | public Color HoverColor | |
1364 | - | public object Value |
1364 | + | |
1365 | get { return _hoverColor; } | |
1366 | - | get { return _value; } |
1366 | + | set { _hoverColor = value; } |
1367 | - | set { _value = value; } |
1367 | + | |
1368 | ||
1369 | public string Text | |
1370 | - | public int RowIndex |
1370 | + | |
1371 | get { return _text; } | |
1372 | - | get { return _rowIndex; } |
1372 | + | set { _text = value; } |
1373 | - | set { _rowIndex = value; } |
1373 | + | |
1374 | ||
1375 | public object Value | |
1376 | - | public bool HideFromMouseMove |
1376 | + | |
1377 | get { return _value; } | |
1378 | - | get { return _hideFromMouseMove; } |
1378 | + | set { _value = value; } |
1379 | - | set { _hideFromMouseMove = value; } |
1379 | + | |
1380 | ||
1381 | public int RowIndex | |
1382 | - | internal Location TopLocation |
1382 | + | |
1383 | get { return _rowIndex; } | |
1384 | - | get { return _topLocation; } |
1384 | + | set { _rowIndex = value; } |
1385 | - | set { _topLocation = value; } |
1385 | + | |
1386 | ||
1387 | public bool HideFromMouseMove | |
1388 | - | internal Location BottomLocation |
1388 | + | |
1389 | get { return _hideFromMouseMove; } | |
1390 | - | get { return _bottomLocation; } |
1390 | + | set { _hideFromMouseMove = value; } |
1391 | - | set { _bottomLocation = value; } |
1391 | + | |
1392 | ||
1393 | internal Location TopLocation | |
1394 | { | |
1395 | get { return _topLocation; } | |
1396 | - | #endregion |
1396 | + | set { _topLocation = value; } |
1397 | } | |
1398 | - | #region "Headers" |
1398 | + | |
1399 | internal Location BottomLocation | |
1400 | - | private class Header |
1400 | + | |
1401 | get { return _bottomLocation; } | |
1402 | set { _bottomLocation = value; } | |
1403 | - | private string _headerText; |
1403 | + | |
1404 | - | private int _startLocation; |
1404 | + | |
1405 | - | private string _headerTextInsteadOfTime = ""; |
1405 | + | } |
1406 | ||
1407 | - | private System.DateTime _time; |
1407 | + | #endregion |
1408 | - | public string HeaderText |
1408 | + | |
1409 | #region "Headers" | |
1410 | - | get { return _headerText; } |
1410 | + | |
1411 | - | set { _headerText = value; } |
1411 | + | private class Header |
1412 | { | |
1413 | ||
1414 | - | public int StartLocation |
1414 | + | private string _headerText; |
1415 | private int _startLocation; | |
1416 | - | get { return _startLocation; } |
1416 | + | private string _headerTextInsteadOfTime = ""; |
1417 | - | set { _startLocation = value; } |
1417 | + | |
1418 | private System.DateTime _time; | |
1419 | public string HeaderText | |
1420 | - | /// <summary> |
1420 | + | |
1421 | - | /// If this string is larger than 0, this will be used instead of Time |
1421 | + | get { return _headerText; } |
1422 | - | /// </summary> |
1422 | + | set { _headerText = value; } |
1423 | - | /// <value></value> |
1423 | + | |
1424 | - | /// <returns></returns> |
1424 | + | |
1425 | - | /// <remarks></remarks> |
1425 | + | public int StartLocation |
1426 | { | |
1427 | - | public string HeaderTextInsteadOfTime |
1427 | + | get { return _startLocation; } |
1428 | set { _startLocation = value; } | |
1429 | - | get { return _headerTextInsteadOfTime; } |
1429 | + | |
1430 | - | set { _headerTextInsteadOfTime = value; } |
1430 | + | |
1431 | /// <summary> | |
1432 | /// If this string is larger than 0, this will be used instead of Time | |
1433 | - | /// <summary> |
1433 | + | |
1434 | - | /// Time to display |
1434 | + | |
1435 | - | /// </summary> |
1435 | + | |
1436 | - | /// <value></value> |
1436 | + | |
1437 | - | /// <returns></returns> |
1437 | + | |
1438 | - | /// <remarks></remarks> |
1438 | + | public string HeaderTextInsteadOfTime |
1439 | { | |
1440 | - | public System.DateTime Time |
1440 | + | get { return _headerTextInsteadOfTime; } |
1441 | set { _headerTextInsteadOfTime = value; } | |
1442 | - | get { return _time; } |
1442 | + | |
1443 | - | set { _time = value; } |
1443 | + | |
1444 | /// <summary> | |
1445 | /// Time to display | |
1446 | /// </summary> | |
1447 | /// <value></value> | |
1448 | - | #endregion |
1448 | + | |
1449 | /// <remarks></remarks> | |
1450 | - | #region "Resize" |
1450 | + | |
1451 | public System.DateTime Time | |
1452 | { | |
1453 | - | /// On resize the Gantt Chart is redrawn |
1453 | + | get { return _time; } |
1454 | set { _time = value; } | |
1455 | - | /// <param name="e"></param> |
1455 | + | |
1456 | ||
1457 | } | |
1458 | - | protected override void OnResize(System.EventArgs e) |
1458 | + | |
1459 | #endregion | |
1460 | - | base.OnResize(e); |
1460 | + | |
1461 | #region "Resize" | |
1462 | - | scrollPosition = 0; |
1462 | + | |
1463 | /// <summary> | |
1464 | - | // Used for when the Gantt Chart is saved as an image |
1464 | + | /// On resize the Gantt Chart is redrawn |
1465 | /// </summary> | |
1466 | - | if (lastLineStop > 0) |
1466 | + | /// <param name="e"></param> |
1467 | /// <remarks></remarks> | |
1468 | - | objBmp = new Bitmap(this.Width - barStartRight, lastLineStop, System.Drawing.Imaging.PixelFormat.Format24bppRgb); |
1468 | + | |
1469 | - | objGraphics = Graphics.FromImage(objBmp); |
1469 | + | protected override void OnResize(System.EventArgs e) |
1470 | { | |
1471 | base.OnResize(e); | |
1472 | - | PaintChart(); |
1472 | + | |
1473 | scrollPosition = 0; | |
1474 | ||
1475 | - | #endregion |
1475 | + | // Used for when the Gantt Chart is saved as an image |
1476 | ||
1477 | - | #region "Scrollbar" |
1477 | + | if (lastLineStop > 0) |
1478 | { | |
1479 | - | private int barsViewable = -1; |
1479 | + | |
1480 | - | private int scrollPosition = 0; |
1480 | + | |
1481 | - | private Rectangle topPart; |
1481 | + | |
1482 | - | private Rectangle BottomPart; |
1482 | + | |
1483 | - | private Rectangle scroll; |
1483 | + | PaintChart(); |
1484 | } | |
1485 | - | private Rectangle scrollBarArea; |
1485 | + | |
1486 | - | private bool mouseOverTopPart = false; |
1486 | + | #endregion |
1487 | - | private bool mouseOverBottomPart = false; |
1487 | + | |
1488 | - | private bool mouseOverScrollBar = false; |
1488 | + | #region "Scrollbar" |
1489 | ||
1490 | - | private bool mouseOverScrollBarArea = false; |
1490 | + | private int barsViewable = -1; |
1491 | private int scrollPosition = 0; | |
1492 | - | /// Draws a scrollbar to the component, if there's a need for it |
1492 | + | private Rectangle topPart; |
1493 | private Rectangle BottomPart; | |
1494 | - | /// <param name="grfx"></param> |
1494 | + | private Rectangle scroll; |
1495 | ||
1496 | private Rectangle scrollBarArea; | |
1497 | - | private void DrawScrollBar(Graphics grfx) |
1497 | + | private bool mouseOverTopPart = false; |
1498 | private bool mouseOverBottomPart = false; | |
1499 | - | barsViewable = (this.Height - barStartTop) / (barHeight + barSpace); |
1499 | + | private bool mouseOverScrollBar = false; |
1500 | ||
1501 | - | if (barCount == 0) |
1501 | + | private bool mouseOverScrollBarArea = false; |
1502 | /// <summary> | |
1503 | /// Draws a scrollbar to the component, if there's a need for it | |
1504 | /// </summary> | |
1505 | /// <param name="grfx"></param> | |
1506 | /// <remarks></remarks> | |
1507 | - | // If the scroll area is filled there's no need to show the scrollbar |
1507 | + | |
1508 | private void DrawScrollBar(Graphics grfx) | |
1509 | - | if (scrollHeight >= maxHeight) |
1509 | + | |
1510 | barsViewable = (this.Height - barStartTop) / (barHeight + barSpace); | |
1511 | int barCount = GetIndexChartBar("QQQWWW"); | |
1512 | if (barCount == 0) | |
1513 | return; | |
1514 | - | scrollBarArea = new Rectangle(this.Width - 20, 19, 12, maxHeight); |
1514 | + | |
1515 | - | scroll = new Rectangle(this.Width - 20, 19 + Convert.ToInt32((scrollPosition * scrollSpeed)), 12, Convert.ToInt32(scrollHeight)); |
1515 | + | int maxHeight = this.Height - 30; |
1516 | decimal scrollHeight = (maxHeight / barCount) * barsViewable; | |
1517 | - | topPart = new Rectangle(this.Width - 20, 10, 12, 8); |
1517 | + | |
1518 | - | BottomPart = new Rectangle(this.Width - 20, this.Height - 10, 12, 8); |
1518 | + | // If the scroll area is filled there's no need to show the scrollbar |
1519 | ||
1520 | - | Brush colorTopPart = null; |
1520 | + | if (scrollHeight >= maxHeight) |
1521 | - | Brush colorBottomPart = null; |
1521 | + | return; |
1522 | - | Brush colorScroll = null; |
1522 | + | |
1523 | decimal scrollSpeed = (maxHeight - scrollHeight) / (barCount - barsViewable); | |
1524 | - | if (mouseOverTopPart == true) |
1524 | + | |
1525 | scrollBarArea = new Rectangle(this.Width - 20, 19, 12, maxHeight); | |
1526 | - | colorTopPart = Brushes.Black; |
1526 | + | scroll = new Rectangle(this.Width - 20, 19 + Convert.ToInt32((scrollPosition * scrollSpeed)), 12, Convert.ToInt32(scrollHeight)); |
1527 | ||
1528 | topPart = new Rectangle(this.Width - 20, 10, 12, 8); | |
1529 | BottomPart = new Rectangle(this.Width - 20, this.Height - 10, 12, 8); | |
1530 | - | colorTopPart = Brushes.Gray; |
1530 | + | |
1531 | Brush colorTopPart = null; | |
1532 | Brush colorBottomPart = null; | |
1533 | Brush colorScroll = null; | |
1534 | ||
1535 | - | colorBottomPart = Brushes.Black; |
1535 | + | if (mouseOverTopPart == true) |
1536 | { | |
1537 | colorTopPart = Brushes.Black; | |
1538 | } | |
1539 | - | colorBottomPart = Brushes.Gray; |
1539 | + | else |
1540 | { | |
1541 | colorTopPart = Brushes.Gray; | |
1542 | - | if (mouseOverScrollBar == true) |
1542 | + | |
1543 | ||
1544 | - | colorScroll = new LinearGradientBrush(scroll, Color.Bisque, Color.Gray, LinearGradientMode.Horizontal); |
1544 | + | if (mouseOverBottomPart == true) |
1545 | { | |
1546 | colorBottomPart = Brushes.Black; | |
1547 | } | |
1548 | - | colorScroll = new LinearGradientBrush(scroll, Color.White, Color.Gray, LinearGradientMode.Horizontal); |
1548 | + | else |
1549 | { | |
1550 | colorBottomPart = Brushes.Gray; | |
1551 | - | // Draws the top and bottom part of the scrollbar |
1551 | + | |
1552 | ||
1553 | - | grfx.DrawRectangle(Pens.Black, topPart); |
1553 | + | if (mouseOverScrollBar == true) |
1554 | - | grfx.FillRectangle(Brushes.LightGray, topPart); |
1554 | + | |
1555 | colorScroll = new LinearGradientBrush(scroll, Color.Bisque, Color.Gray, LinearGradientMode.Horizontal); | |
1556 | - | grfx.DrawRectangle(Pens.Black, BottomPart); |
1556 | + | |
1557 | - | grfx.FillRectangle(Brushes.LightGray, BottomPart); |
1557 | + | else |
1558 | { | |
1559 | - | // Draws arrows |
1559 | + | colorScroll = new LinearGradientBrush(scroll, Color.White, Color.Gray, LinearGradientMode.Horizontal); |
1560 | } | |
1561 | - | PointF[] points = new PointF[3]; |
1561 | + | |
1562 | - | points[0] = new PointF(topPart.Left, topPart.Bottom - 1); |
1562 | + | // Draws the top and bottom part of the scrollbar |
1563 | - | points[1] = new PointF(topPart.Right, topPart.Bottom - 1); |
1563 | + | |
1564 | - | points[2] = new PointF((topPart.Left + topPart.Right) / 2, topPart.Top + 1); |
1564 | + | grfx.DrawRectangle(Pens.Black, topPart); |
1565 | grfx.FillRectangle(Brushes.LightGray, topPart); | |
1566 | - | grfx.FillPolygon(colorTopPart, points); |
1566 | + | |
1567 | grfx.DrawRectangle(Pens.Black, BottomPart); | |
1568 | - | points[0] = new PointF(BottomPart.Left, BottomPart.Top + 1); |
1568 | + | grfx.FillRectangle(Brushes.LightGray, BottomPart); |
1569 | - | points[1] = new PointF(BottomPart.Right, BottomPart.Top + 1); |
1569 | + | |
1570 | - | points[2] = new PointF((BottomPart.Left + BottomPart.Right) / 2, BottomPart.Bottom - 1); |
1570 | + | // Draws arrows |
1571 | ||
1572 | - | grfx.FillPolygon(colorBottomPart, points); |
1572 | + | PointF[] points = new PointF[3]; |
1573 | points[0] = new PointF(topPart.Left, topPart.Bottom - 1); | |
1574 | - | // Draws the scroll area |
1574 | + | points[1] = new PointF(topPart.Right, topPart.Bottom - 1); |
1575 | points[2] = new PointF((topPart.Left + topPart.Right) / 2, topPart.Top + 1); | |
1576 | - | grfx.DrawRectangle(Pens.Black, scrollBarArea); |
1576 | + | |
1577 | - | grfx.FillRectangle(Brushes.DarkGray, scrollBarArea); |
1577 | + | grfx.FillPolygon(colorTopPart, points); |
1578 | ||
1579 | - | // Draws the actual scrollbar |
1579 | + | points[0] = new PointF(BottomPart.Left, BottomPart.Top + 1); |
1580 | points[1] = new PointF(BottomPart.Right, BottomPart.Top + 1); | |
1581 | - | grfx.DrawRectangle(Pens.Black, scroll); |
1581 | + | points[2] = new PointF((BottomPart.Left + BottomPart.Right) / 2, BottomPart.Bottom - 1); |
1582 | - | grfx.FillRectangle(colorScroll, scroll); |
1582 | + | |
1583 | grfx.FillPolygon(colorBottomPart, points); | |
1584 | ||
1585 | // Draws the scroll area | |
1586 | - | /// The Y-position of the center of the scroll |
1586 | + | |
1587 | grfx.DrawRectangle(Pens.Black, scrollBarArea); | |
1588 | grfx.FillRectangle(Brushes.DarkGray, scrollBarArea); | |
1589 | ||
1590 | // Draws the actual scrollbar | |
1591 | ||
1592 | - | private int ScrollPositionY |
1592 | + | grfx.DrawRectangle(Pens.Black, scroll); |
1593 | grfx.FillRectangle(colorScroll, scroll); | |
1594 | - | get |
1594 | + | } |
1595 | ||
1596 | - | if (scroll == null) |
1596 | + | |
1597 | - | return -1; |
1597 | + | /// The Y-position of the center of the scroll |
1598 | - | return ((scroll.Height / 2) + scroll.Location.Y) + 19; |
1598 | + | |
1599 | /// <value></value> | |
1600 | - | set |
1600 | + | /// <returns></returns> |
1601 | /// <remarks></remarks> | |
1602 | - | int barCount = GetIndexChartBar("QQQWWW"); |
1602 | + | |
1603 | - | int maxHeight = this.Height - 30; |
1603 | + | private int ScrollPositionY |
1604 | - | decimal scrollHeight = (maxHeight / barCount) * barsViewable; |
1604 | + | |
1605 | - | decimal scrollSpeed = (maxHeight - scrollHeight) / (barCount - barsViewable); |
1605 | + | get |
1606 | - | int index = 0; |
1606 | + | |
1607 | - | dynamic distanceFromLastPosition = 9999; |
1607 | + | if (scroll == null) |
1608 | return -1; | |
1609 | - | // Tests to see what scrollposition is the closest to the set position |
1609 | + | return ((scroll.Height / 2) + scroll.Location.Y) + 19; |
1610 | } | |
1611 | - | while (index < barCount) |
1611 | + | set |
1612 | { | |
1613 | - | int newPositionTemp = Convert.ToInt32((index * scrollSpeed) + (scrollHeight / 2) + (30 / 2)); |
1613 | + | |
1614 | - | dynamic distanceFromCurrentPosition = newPositionTemp - value; |
1614 | + | |
1615 | decimal scrollHeight = (maxHeight / barCount) * barsViewable; | |
1616 | - | if (distanceFromLastPosition < 0) |
1616 | + | |
1617 | int index = 0; | |
1618 | - | if (distanceFromCurrentPosition < distanceFromLastPosition) |
1618 | + | dynamic distanceFromLastPosition = 9999; |
1619 | ||
1620 | - | scrollPosition = index - 1; |
1620 | + | // Tests to see what scrollposition is the closest to the set position |
1621 | - | PaintChart(); |
1621 | + | |
1622 | - | return; |
1622 | + | while (index < barCount) |
1623 | { | |
1624 | int newPositionTemp = Convert.ToInt32((index * scrollSpeed) + (scrollHeight / 2) + (30 / 2)); | |
1625 | - | else |
1625 | + | dynamic distanceFromCurrentPosition = newPositionTemp - value; |
1626 | ||
1627 | - | if (distanceFromCurrentPosition > distanceFromLastPosition) |
1627 | + | if (distanceFromLastPosition < 0) |
1628 | { | |
1629 | - | scrollPosition = index - 1; |
1629 | + | if (distanceFromCurrentPosition < distanceFromLastPosition) |
1630 | { | |
1631 | - | // A precaution to make sure the scroll bar doesn't go too far down |
1631 | + | scrollPosition = index - 1; |
1632 | PaintChart(); | |
1633 | - | if (scrollPosition + barsViewable > GetIndexChartBar("QQQWWW")) |
1633 | + | return; |
1634 | - | { |
1634 | + | |
1635 | - | scrollPosition = GetIndexChartBar("QQQWWW") - barsViewable; |
1635 | + | |
1636 | - | } |
1636 | + | |
1637 | { | |
1638 | - | PaintChart(); |
1638 | + | if (distanceFromCurrentPosition > distanceFromLastPosition) |
1639 | - | return; |
1639 | + | |
1640 | scrollPosition = index - 1; | |
1641 | ||
1642 | // A precaution to make sure the scroll bar doesn't go too far down | |
1643 | - | distanceFromLastPosition = distanceFromCurrentPosition; |
1643 | + | |
1644 | if (scrollPosition + barsViewable > GetIndexChartBar("QQQWWW")) | |
1645 | - | index += 1; |
1645 | + | |
1646 | scrollPosition = GetIndexChartBar("QQQWWW") - barsViewable; | |
1647 | } | |
1648 | ||
1649 | PaintChart(); | |
1650 | return; | |
1651 | - | /// Scrolls one row up |
1651 | + | |
1652 | } | |
1653 | ||
1654 | distanceFromLastPosition = distanceFromCurrentPosition; | |
1655 | - | public void ScrollOneup() |
1655 | + | |
1656 | index += 1; | |
1657 | - | if (scrollPosition == 0) |
1657 | + | |
1658 | } | |
1659 | } | |
1660 | - | scrollPosition -= 1; |
1660 | + | |
1661 | /// <summary> | |
1662 | - | PaintChart(); |
1662 | + | /// Scrolls one row up |
1663 | /// </summary> | |
1664 | /// <remarks></remarks> | |
1665 | ||
1666 | - | /// Scrolls one row down |
1666 | + | public void ScrollOneup() |
1667 | { | |
1668 | if (scrollPosition == 0) | |
1669 | return; | |
1670 | - | public void ScrollOneDown() |
1670 | + | |
1671 | scrollPosition -= 1; | |
1672 | - | if (scrollPosition + barsViewable >= GetIndexChartBar("QQQWWW")) |
1672 | + | |
1673 | PaintChart(); | |
1674 | } | |
1675 | - | scrollPosition += 1; |
1675 | + | |
1676 | /// <summary> | |
1677 | - | PaintChart(); |
1677 | + | /// Scrolls one row down |
1678 | /// </summary> | |
1679 | /// <remarks></remarks> | |
1680 | ||
1681 | - | /// If the user clicks on the scrollbar, scrolling functions will be called |
1681 | + | public void ScrollOneDown() |
1682 | { | |
1683 | - | /// <param name="sender"></param> |
1683 | + | if (scrollPosition + barsViewable >= GetIndexChartBar("QQQWWW")) |
1684 | - | /// <param name="e"></param> |
1684 | + | return; |
1685 | ||
1686 | scrollPosition += 1; | |
1687 | - | private void GanttChart_Click(System.Object sender, System.Windows.Forms.MouseEventArgs e) |
1687 | + | |
1688 | PaintChart(); | |
1689 | - | if (e.Button == System.Windows.Forms.MouseButtons.Left) |
1689 | + | } |
1690 | ||
1691 | - | if (mouseOverBottomPart == true) |
1691 | + | |
1692 | /// If the user clicks on the scrollbar, scrolling functions will be called | |
1693 | - | ScrollOneDown(); |
1693 | + | |
1694 | /// <param name="sender"></param> | |
1695 | - | else if (mouseOverTopPart == true) |
1695 | + | /// <param name="e"></param> |
1696 | /// <remarks></remarks> | |
1697 | - | ScrollOneup(); |
1697 | + | |
1698 | private void GanttChart_Click(System.Object sender, System.Windows.Forms.MouseEventArgs e) | |
1699 | { | |
1700 | if (e.Button == System.Windows.Forms.MouseButtons.Left) | |
1701 | { | |
1702 | if (mouseOverBottomPart == true) | |
1703 | - | /// When mousewheel is used, the scrollbar will scroll |
1703 | + | |
1704 | ScrollOneDown(); | |
1705 | - | /// <param name="sender"></param> |
1705 | + | |
1706 | - | /// <param name="e"></param> |
1706 | + | else if (mouseOverTopPart == true) |
1707 | { | |
1708 | ScrollOneup(); | |
1709 | - | private void GanttChart_MouseWheel(object sender, System.Windows.Forms.MouseEventArgs e) |
1709 | + | |
1710 | } | |
1711 | - | if (e.Delta > 0) |
1711 | + | } |
1712 | ||
1713 | /// <summary> | |
1714 | /// When mousewheel is used, the scrollbar will scroll | |
1715 | /// </summary> | |
1716 | /// <param name="sender"></param> | |
1717 | /// <param name="e"></param> | |
1718 | /// <remarks></remarks> | |
1719 | ||
1720 | private void GanttChart_MouseWheel(object sender, System.Windows.Forms.MouseEventArgs e) | |
1721 | - | #endregion |
1721 | + | |
1722 | if (e.Delta > 0) | |
1723 | - | #region "Save" |
1723 | + | |
1724 | ScrollOneup(); | |
1725 | } | |
1726 | - | /// Saves the GanttChart to specified image file |
1726 | + | else |
1727 | { | |
1728 | - | /// <param name="filePath"></param> |
1728 | + | ScrollOneDown(); |
1729 | } | |
1730 | } | |
1731 | - | public void SaveImage(string filePath) |
1731 | + | |
1732 | #endregion | |
1733 | - | objGraphics.SmoothingMode = SmoothingMode.HighSpeed; |
1733 | + | |
1734 | - | objGraphics.Clear(this.BackColor); |
1734 | + | #region "Save" |
1735 | ||
1736 | - | if (headerFromDate == null | headerToDate == null) |
1736 | + | |
1737 | /// Saves the GanttChart to specified image file | |
1738 | /// </summary> | |
1739 | - | DrawHeader(objGraphics, null); |
1739 | + | /// <param name="filePath"></param> |
1740 | - | DrawNetHorizontal(objGraphics); |
1740 | + | /// <remarks></remarks> |
1741 | - | DrawNetVertical(objGraphics); |
1741 | + | |
1742 | - | DrawBars(objGraphics, true); |
1742 | + | public void SaveImage(string filePath) |
1743 | { | |
1744 | - | objBmp.Save(filePath); |
1744 | + | objGraphics.SmoothingMode = SmoothingMode.HighSpeed; |
1745 | objGraphics.Clear(this.BackColor); | |
1746 | ||
1747 | - | #endregion |
1747 | + | if (headerFromDate == null | headerToDate == null) |
1748 | return; | |
1749 | - | private enum MouseOverPart |
1749 | + | |
1750 | DrawHeader(objGraphics, null); | |
1751 | DrawNetHorizontal(objGraphics); | |
1752 | - | Empty, |
1752 | + | DrawNetVertical(objGraphics); |
1753 | - | Bar, |
1753 | + | DrawBars(objGraphics, true); |
1754 | - | BarLeftSide, |
1754 | + | |
1755 | - | BarRightSide |
1755 | + | objBmp.Save(filePath); |
1756 | } | |
1757 | ||
1758 | #endregion | |
1759 | - | } |
1759 | + | |
1760 | private enum MouseOverPart | |
1761 | { | |
1762 | ||
1763 | Empty, | |
1764 | Bar, | |
1765 | BarLeftSide, | |
1766 | BarRightSide | |
1767 | ||
1768 | } | |
1769 | ||
1770 | } |