GanttChart
A Gantt chart: a task list beside a timeline of bars, milestones and links, scheduled by the critical-path method and editable with the mouse or the keyboard.
public partial class GanttChart : Control
Inherits from / implements: Control
Remarks
Give the chart a list of ProjectTask objects in Tasks and the dependencies between them in Links. The chart works the dates out on the working calendar set by WorkingWeek and Holidays, draws the critical path, and redraws itself when the objects change. A reader can drag a bar to move it, drag its end to change its length, drag the small triangle under it to record progress, and drag from the dot at its end to another bar to link the two. Everything the mouse can do the keyboard can too: Shift and an arrow moves a task a working day, Ctrl+Shift and an arrow changes its length, and F2 edits a cell of the task list - including the predecessors, typed as a planner writes them ( 2, 3SS+1 ). Each edit is offered first through TaskChanging or LinksChanging, which an application can cancel, and is then applied to the objects themselves.
Members at a glance
GanttChart | Creates a Gantt chart with an empty plan. |
BackColor | The background of both panes. Defaults to the system window colour, as a list or a grid does, rather than the grey of a dialog. |
BarColor | The colour of a task bar: its finished part, its outline, and (lightened) the rest of it. |
BaselineColor | The colour of the baseline drawn under a bar when ShowBaselines is on. |
Columns | The columns of the task list. The task's name is always shown, whether or not Name is set. |
CriticalBarColor | The colour of the tasks and links on the critical path, when ShowCriticalPath is on. |
GridLineColor | The colour of the lines between rows and columns. Empty, the default, mixes a little of the fore colour into the back colour. |
GridWidth | The width of the task list, in logical units (1/96 inch). The reader can drag the splitter to change it. A task list wider than its columns stretches the name column; a narrower one scrolls sideways. |
HeaderBackColor | The background of the column and date headers. Empty, the default, is a faint tint of the fore colour. |
Holidays | Dates that are not worked, such as public holidays. Never null: setting null gives an empty list. An observable collection is watched; changes to a plain list are seen after Reschedule. |
LinkColor | The colour of the links that are not on the critical path. Empty, the default, is a muted fore colour. |
Links | The links between the tasks. Never null: setting null gives an empty list. |
NonWorkingDayColor | The shading behind weekends and holidays. Empty, the default, is a faint tint of the fore colour. |
ProjectStart | The first day work can happen. Null takes it from the tasks: the earliest planned start, then the earliest planned finish, and failing both, today. |
ReadOnly | Stops the reader changing the plan: bars cannot be dragged, links cannot be drawn and cells cannot be edited. Selecting, scrolling, zooming and opening summaries still work. |
RowHeight | The height of a row, in logical units (1/96 inch). Rows grow beyond it when the font needs more room. |
SelectedTask | The task whose row is selected, or null when there is none. Setting a task opens the summaries it is in and scrolls its row into view; a task that is not in the plan selects nothing. |
ShowBaselines | Draws each task's baseline - its originally agreed dates - as a thin bar under its current one, so slippage shows at a glance. |
ShowCriticalPath | Draws the tasks and links on the critical path in CriticalBarColor. |
ShowLinks | Draws the links between tasks as arrows on the timeline. |
ShowToday | Draws a line on the timeline at Today. |
SummaryBarColor | The colour of a summary's bracket and of a milestone's diamond. |
Tasks | The tasks of the plan, in outline order within each parent. Never null: setting null gives an empty list. |
Today | The date the today line is drawn at. Null, the default, uses the computer's date. It changes nothing else: the plan is scheduled from ProjectStart, not from today. |
TodayColor | The colour of the today line. |
WeekStart | The day the timeline's weeks start on, at Day and Week zoom. |
WorkingWeek | The days of the week that are worked. Durations and lags count only these days, and the others are shaded on the timeline. |
Zoom | How much time the timeline shows, from a column per day to a column per half-year. The date in the middle of the timeline stays in the middle when it changes. |
CollapseAll | Closes every summary task. A selected task inside one passes the selection to its top-level summary. |
CreateAccessibilityInstance | Creates the accessible object that exposes the rows to screen readers and other assistive technology. |
CreatePrintDocument | Creates a document that prints the whole chart, shrunk to the width of the page when it is not much wider, and otherwise across as many pages as it needs, with the headers repeated on each page and every page ending on a whole row. |
Dispose | Stops watching the plan and releases the fonts, the tooltip and the timers the chart created. The scroll bars and the cell editor are child controls and are released by the base class. |
EnsureSchedule | The plan as scheduled: every task's dates and float, the links that were honoured, the critical path, and anything in the input that could not be used. |
ExpandAll | Opens every summary task. |
ExportImage | Draws the whole chart - every task with every summary open, and the whole timeline - into a new image at 96 DPI, with the task list and the timeline side by side. |
IsExpanded | Whether a summary task's subtasks are shown. |
IsInputKey | — |
OnBackColorChanged | — |
OnDpiChangedAfterParent | — |
OnFontChanged | — |
OnForeColorChanged | — |
OnGotFocus | — |
OnHandleCreated | — |
OnHandleDestroyed | — |
OnKeyDown | — |
OnLinksChanged | Raises LinksChanged. |
OnLinksChanging | Raises LinksChanging. |
OnLostFocus | — |
OnMouseCaptureChanged | — |
OnMouseDoubleClick | — |
OnMouseDown | — |
OnMouseLeave | — |
OnMouseMove | — |
OnMouseUp | — |
OnMouseWheel | — |
OnPaint | — |
OnResize | — |
OnScheduleChanged | Raises ScheduleChanged. |
OnSelectedTaskChanged | Raises SelectedTaskChanged. |
OnTaskActivated | Raises TaskActivated. |
OnTaskChanged | Raises TaskChanged. |
OnTaskChanging | Raises TaskChanging. |
OnTaskToggled | Raises TaskToggled. |
OnZoomChanged | Raises ZoomChanged. |
Reschedule | Schedules the plan again now and raises ScheduleChanged. Needed only after changing a plain list, which the chart cannot watch; observable collections and the task and link objects themselves are watched. |
ResetBackColor | Returns BackColor to the system window colour. |
ScrollToTask | Scrolls a task's row and bar into view, opening the summaries it is in. The selection is left as it is; set SelectedTask to select the task as well. |
ScrollToToday | Scrolls the timeline so that today is a third of the way across it. |
SetExpanded | Opens or closes a summary task. Nothing happens for a task that is not a summary in the plan. |
Size | The size the chart is given when it is first placed on a form: room for the task list and a few weeks. |
ZoomIn | Shows less time in more detail: one step finer, stopping at Day. |
ZoomOut | Shows more time in less detail: one step coarser, stopping at Year. |
ZoomToFit | Picks the finest zoom that shows the whole plan across the timeline without scrolling sideways, and scrolls to the plan's start. |
LinksChanged | Raised after links the reader added or removed have been applied to Links. |
LinksChanging | Raised before links are added or removed by the reader - a link drawn between two bars, a predecessor list typed into a cell, or a selected link deleted. Set Cancel to refuse the change. |
ScheduleChanged | Raised after the plan has been scheduled again because something in it changed. It is raised from the message loop, once for any number of changes made together. |
SelectedTaskChanged | Raised when SelectedTask changes. |
TaskActivated | Raised when the reader double-clicks a task, or presses Enter or Space on its row. |
TaskChanged | Raised after a change the reader made has been applied to a task. |
TaskChanging | Raised before a task is changed by the reader - moved, resized, given progress or edited in a cell. Set Cancel to refuse the change. |
TaskToggled | Raised when a summary task is opened or closed. |
ZoomChanged | Raised when Zoom changes. |
Constructors
GanttChart
Creates a Gantt chart with an empty plan.
Properties
BackColor
The background of both panes. Defaults to the system window colour, as a list or a grid does, rather than the grey of a dialog.
BarColor
The colour of a task bar: its finished part, its outline, and (lightened) the rest of it.
BaselineColor
The colour of the baseline drawn under a bar when ShowBaselines is on.
Columns
The columns of the task list. The task's name is always shown, whether or not Name is set.
CriticalBarColor
The colour of the tasks and links on the critical path, when ShowCriticalPath is on.
GridLineColor
The colour of the lines between rows and columns. Empty, the default, mixes a little of the fore colour into the back colour.
GridWidth
The width of the task list, in logical units (1/96 inch). The reader can drag the splitter to change it. A task list wider than its columns stretches the name column; a narrower one scrolls sideways.
- ArgumentOutOfRangeException
- The value is negative.
HeaderBackColor
The background of the column and date headers. Empty, the default, is a faint tint of the fore colour.
Holidays
Dates that are not worked, such as public holidays. Never null: setting null gives an empty list. An observable collection is watched; changes to a plain list are seen after Reschedule.
LinkColor
The colour of the links that are not on the critical path. Empty, the default, is a muted fore colour.
Links
The links between the tasks. Never null: setting null gives an empty list.
Tasks. Links the reader draws or types are added to this list, and links the reader removes are removed from it, after LinksChanging has allowed it; a read-only list is never changed.NonWorkingDayColor
The shading behind weekends and holidays. Empty, the default, is a faint tint of the fore colour.
ProjectStart
The first day work can happen. Null takes it from the tasks: the earliest planned start, then the earliest planned finish, and failing both, today.
ReadOnly
Stops the reader changing the plan: bars cannot be dragged, links cannot be drawn and cells cannot be edited. Selecting, scrolling, zooming and opening summaries still work.
RowHeight
The height of a row, in logical units (1/96 inch). Rows grow beyond it when the font needs more room.
- ArgumentOutOfRangeException
- The value is below 12 or above 400.
SelectedTask
The task whose row is selected, or null when there is none. Setting a task opens the summaries it is in and scrolls its row into view; a task that is not in the plan selects nothing.
ShowBaselines
Draws each task's baseline - its originally agreed dates - as a thin bar under its current one, so slippage shows at a glance.
ShowCriticalPath
Draws the tasks and links on the critical path in CriticalBarColor.
ShowLinks
Draws the links between tasks as arrows on the timeline.
ShowToday
Draws a line on the timeline at Today.
SummaryBarColor
The colour of a summary's bracket and of a milestone's diamond.
Tasks
The tasks of the plan, in outline order within each parent. Never null: setting null gives an empty list.
ObservableCollection{T} or a BindingList{T} is watched, so adding, removing and changing tasks redraws the chart. A plain list is read when it is assigned; call Reschedule after changing one.Today
The date the today line is drawn at. Null, the default, uses the computer's date. It changes nothing else: the plan is scheduled from ProjectStart, not from today.
TodayColor
The colour of the today line.
WeekStart
The day the timeline's weeks start on, at Day and Week zoom.
- InvalidEnumArgumentException
- The value is not a
DayOfWeek.
WorkingWeek
The days of the week that are worked. Durations and lags count only these days, and the others are shaded on the timeline.
Zoom
How much time the timeline shows, from a column per day to a column per half-year. The date in the middle of the timeline stays in the middle when it changes.
- InvalidEnumArgumentException
- The value is not a
GanttZoom.
Methods
CollapseAll
Closes every summary task. A selected task inside one passes the selection to its top-level summary.
CreateAccessibilityInstance
Creates the accessible object that exposes the rows to screen readers and other assistive technology.
Returns. The chart's accessible object.
CreatePrintDocument
Creates a document that prints the whole chart, shrunk to the width of the page when it is not much wider, and otherwise across as many pages as it needs, with the headers repeated on each page and every page ending on a whole row.
Returns. The document. The caller owns it and disposes it.
Dispose
Stops watching the plan and releases the fonts, the tooltip and the timers the chart created. The scroll bars and the cell editor are child controls and are released by the base class.
- disposing
- True when called from
Dispose().
EnsureSchedule
The plan as scheduled: every task's dates and float, the links that were honoured, the critical path, and anything in the input that could not be used.
ExpandAll
Opens every summary task.
ExportImage
Draws the whole chart - every task with every summary open, and the whole timeline - into a new image at 96 DPI, with the task list and the timeline side by side.
Returns. The image. The caller owns it and disposes it.
- InvalidOperationException
- The plan is too large for one image; print it with
CreatePrintDocumentinstead.
IsExpanded
Whether a summary task's subtasks are shown.
- task
- The task.
Returns. True for an open summary; false for a closed one, a task that is not a summary, or one not in the plan.
IsInputKey
No summary in the source yet.
OnBackColorChanged
No summary in the source yet.
OnDpiChangedAfterParent
No summary in the source yet.
OnFontChanged
No summary in the source yet.
OnForeColorChanged
No summary in the source yet.
OnGotFocus
No summary in the source yet.
OnHandleCreated
No summary in the source yet.
OnHandleDestroyed
No summary in the source yet.
OnKeyDown
No summary in the source yet.
OnLinksChanged
Raises LinksChanged.
- e
- Empty event data.
OnLinksChanging
Raises LinksChanging.
- e
- The proposed change.
OnLostFocus
No summary in the source yet.
OnMouseCaptureChanged
No summary in the source yet.
OnMouseDoubleClick
No summary in the source yet.
OnMouseDown
No summary in the source yet.
OnMouseLeave
No summary in the source yet.
OnMouseMove
No summary in the source yet.
OnMouseUp
No summary in the source yet.
OnMouseWheel
No summary in the source yet.
OnPaint
No summary in the source yet.
OnResize
No summary in the source yet.
OnScheduleChanged
Raises ScheduleChanged.
- e
- Empty event data.
OnSelectedTaskChanged
Raises SelectedTaskChanged.
- e
- Empty event data.
OnTaskActivated
Raises TaskActivated.
- e
- The task that was activated.
OnTaskChanged
Raises TaskChanged.
- e
- The task that changed.
OnTaskChanging
Raises TaskChanging.
- e
- The proposed change.
OnTaskToggled
Raises TaskToggled.
- e
- The summary that was opened or closed.
OnZoomChanged
Raises ZoomChanged.
- e
- Empty event data.
Reschedule
Schedules the plan again now and raises ScheduleChanged. Needed only after changing a plain list, which the chart cannot watch; observable collections and the task and link objects themselves are watched.
ResetBackColor
Returns BackColor to the system window colour.
ScrollToTask
Scrolls a task's row and bar into view, opening the summaries it is in. The selection is left as it is; set SelectedTask to select the task as well.
- task
- The task. Nothing happens for null or a task that is not in the plan.
ScrollToToday
Scrolls the timeline so that today is a third of the way across it.
SetExpanded
Opens or closes a summary task. Nothing happens for a task that is not a summary in the plan.
- task
- The summary.
- expanded
- True to show its subtasks, false to hide them.
Size
The size the chart is given when it is first placed on a form: room for the task list and a few weeks.
ZoomIn
Shows less time in more detail: one step finer, stopping at Day.
ZoomOut
Shows more time in less detail: one step coarser, stopping at Year.
ZoomToFit
Picks the finest zoom that shows the whole plan across the timeline without scrolling sideways, and scrolls to the plan's start.
Events
LinksChanged
Raised after links the reader added or removed have been applied to Links.
LinksChanging
Raised before links are added or removed by the reader - a link drawn between two bars, a predecessor list typed into a cell, or a selected link deleted. Set Cancel to refuse the change.
ScheduleChanged
Raised after the plan has been scheduled again because something in it changed. It is raised from the message loop, once for any number of changes made together.
SelectedTaskChanged
Raised when SelectedTask changes.
TaskActivated
Raised when the reader double-clicks a task, or presses Enter or Space on its row.
TaskChanged
Raised after a change the reader made has been applied to a task.
TaskChanging
Raised before a task is changed by the reader - moved, resized, given progress or edited in a cell. Set Cancel to refuse the change.
TaskToggled
Raised when a summary task is opened or closed.
ZoomChanged
Raised when Zoom changes.