HypernovaDesktop Components · docs
Binarymission
WinForms › Project Management › GanttChart

GanttChart

class.NET 6 / 8 / 10.NET Framework 4.8Binarymission.WinForms.Controls.ProjectManagement

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

GanttChartCreates a Gantt chart with an empty plan.
BackColorThe background of both panes. Defaults to the system window colour, as a list or a grid does, rather than the grey of a dialog.
BarColorThe colour of a task bar: its finished part, its outline, and (lightened) the rest of it.
BaselineColorThe colour of the baseline drawn under a bar when ShowBaselines is on.
ColumnsThe columns of the task list. The task's name is always shown, whether or not Name is set.
CriticalBarColorThe colour of the tasks and links on the critical path, when ShowCriticalPath is on.
GridLineColorThe colour of the lines between rows and columns. Empty, the default, mixes a little of the fore colour into the back colour.
GridWidthThe 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.
HeaderBackColorThe background of the column and date headers. Empty, the default, is a faint tint of the fore colour.
HolidaysDates 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.
LinkColorThe colour of the links that are not on the critical path. Empty, the default, is a muted fore colour.
LinksThe links between the tasks. Never null: setting null gives an empty list.
NonWorkingDayColorThe shading behind weekends and holidays. Empty, the default, is a faint tint of the fore colour.
ProjectStartThe first day work can happen. Null takes it from the tasks: the earliest planned start, then the earliest planned finish, and failing both, today.
ReadOnlyStops 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.
RowHeightThe height of a row, in logical units (1/96 inch). Rows grow beyond it when the font needs more room.
SelectedTaskThe 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.
ShowBaselinesDraws each task's baseline - its originally agreed dates - as a thin bar under its current one, so slippage shows at a glance.
ShowCriticalPathDraws the tasks and links on the critical path in CriticalBarColor.
ShowLinksDraws the links between tasks as arrows on the timeline.
ShowTodayDraws a line on the timeline at Today.
SummaryBarColorThe colour of a summary's bracket and of a milestone's diamond.
TasksThe tasks of the plan, in outline order within each parent. Never null: setting null gives an empty list.
TodayThe 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.
TodayColorThe colour of the today line.
WeekStartThe day the timeline's weeks start on, at Day and Week zoom.
WorkingWeekThe days of the week that are worked. Durations and lags count only these days, and the others are shaded on the timeline.
ZoomHow 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.
CollapseAllCloses every summary task. A selected task inside one passes the selection to its top-level summary.
CreateAccessibilityInstanceCreates the accessible object that exposes the rows to screen readers and other assistive technology.
CreatePrintDocumentCreates 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.
DisposeStops 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.
EnsureScheduleThe 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.
ExpandAllOpens every summary task.
ExportImageDraws 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.
IsExpandedWhether a summary task's subtasks are shown.
IsInputKey—
OnBackColorChanged—
OnDpiChangedAfterParent—
OnFontChanged—
OnForeColorChanged—
OnGotFocus—
OnHandleCreated—
OnHandleDestroyed—
OnKeyDown—
OnLinksChangedRaises LinksChanged.
OnLinksChangingRaises LinksChanging.
OnLostFocus—
OnMouseCaptureChanged—
OnMouseDoubleClick—
OnMouseDown—
OnMouseLeave—
OnMouseMove—
OnMouseUp—
OnMouseWheel—
OnPaint—
OnResize—
OnScheduleChangedRaises ScheduleChanged.
OnSelectedTaskChangedRaises SelectedTaskChanged.
OnTaskActivatedRaises TaskActivated.
OnTaskChangedRaises TaskChanged.
OnTaskChangingRaises TaskChanging.
OnTaskToggledRaises TaskToggled.
OnZoomChangedRaises ZoomChanged.
RescheduleSchedules 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.
ResetBackColorReturns BackColor to the system window colour.
ScrollToTaskScrolls 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.
ScrollToTodayScrolls the timeline so that today is a third of the way across it.
SetExpandedOpens or closes a summary task. Nothing happens for a task that is not a summary in the plan.
SizeThe size the chart is given when it is first placed on a form: room for the task list and a few weeks.
ZoomInShows less time in more detail: one step finer, stopping at Day.
ZoomOutShows more time in less detail: one step coarser, stopping at Year.
ZoomToFitPicks the finest zoom that shows the whole plan across the timeline without scrolling sideways, and scrolls to the plan's start.
LinksChangedRaised after links the reader added or removed have been applied to Links.
LinksChangingRaised 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.
ScheduleChangedRaised 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.
SelectedTaskChangedRaised when SelectedTask changes.
TaskActivatedRaised when the reader double-clicks a task, or presses Enter or Space on its row.
TaskChangedRaised after a change the reader made has been applied to a task.
TaskChangingRaised before a task is changed by the reader - moved, resized, given progress or edited in a cell. Set Cancel to refuse the change.
TaskToggledRaised when a summary task is opened or closed.
ZoomChangedRaised when Zoom changes.

Constructors

GanttChart

public GanttChart()

Creates a Gantt chart with an empty plan.

Properties

BackColor

public override Color 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

public Color BarColor

The colour of a task bar: its finished part, its outline, and (lightened) the rest of it.

BaselineColor

public Color BaselineColor

The colour of the baseline drawn under a bar when ShowBaselines is on.

Columns

public GanttColumns Columns

The columns of the task list. The task's name is always shown, whether or not Name is set.

CriticalBarColor

public Color CriticalBarColor

The colour of the tasks and links on the critical path, when ShowCriticalPath is on.

GridLineColor

public Color 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

public int 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

public Color HeaderBackColor

The background of the column and date headers. Empty, the default, is a faint tint of the fore colour.

Holidays

public IList<DateTime> 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

public Color LinkColor

The colour of the links that are not on the critical path. Empty, the default, is a muted fore colour.

NonWorkingDayColor

public Color NonWorkingDayColor

The shading behind weekends and holidays. Empty, the default, is a faint tint of the fore colour.

ProjectStart

public DateTime? 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

public bool 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

public int 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

public ProjectTask 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

public bool 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

public bool ShowCriticalPath

Draws the tasks and links on the critical path in CriticalBarColor.

ShowToday

public bool ShowToday

Draws a line on the timeline at Today.

SummaryBarColor

public Color SummaryBarColor

The colour of a summary's bracket and of a milestone's diamond.

Tasks

public IList<ProjectTask> Tasks

The tasks of the plan, in outline order within each parent. Never null: setting null gives an empty list.

An 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

public DateTime? 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

public Color TodayColor

The colour of the today line.

WeekStart

public DayOfWeek WeekStart

The day the timeline's weeks start on, at Day and Week zoom.

InvalidEnumArgumentException
The value is not a DayOfWeek.

WorkingWeek

public WorkingWeek 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

public GanttZoom 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

public void CollapseAll()

Closes every summary task. A selected task inside one passes the selection to its top-level summary.

CreateAccessibilityInstance

protected override AccessibleObject CreateAccessibilityInstance()

Creates the accessible object that exposes the rows to screen readers and other assistive technology.

Returns. The chart's accessible object.

CreatePrintDocument

public PrintDocument 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.

The plan is read when printing starts, not when the document is created, so a document kept for a print preview prints the plan as it is at the time.

Dispose

protected override void Dispose(bool disposing)

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

public ProjectSchedule Schedule

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.

Worked out when first asked for after a change, so reading it straight after changing a task gives the new dates.

ExpandAll

public void ExpandAll()

Opens every summary task.

ExportImage

public Bitmap 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 CreatePrintDocument instead.

IsExpanded

public bool IsExpanded(ProjectTask task)

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

protected override bool IsInputKey(Keys keyData)

No summary in the source yet.

OnBackColorChanged

protected override void OnBackColorChanged(EventArgs e)

No summary in the source yet.

OnDpiChangedAfterParent

protected override void OnDpiChangedAfterParent(EventArgs e)

No summary in the source yet.

OnFontChanged

protected override void OnFontChanged(EventArgs e)

No summary in the source yet.

OnForeColorChanged

protected override void OnForeColorChanged(EventArgs e)

No summary in the source yet.

OnGotFocus

protected override void OnGotFocus(EventArgs e)

No summary in the source yet.

OnHandleCreated

protected override void OnHandleCreated(EventArgs e)

No summary in the source yet.

OnHandleDestroyed

protected override void OnHandleDestroyed(EventArgs e)

No summary in the source yet.

OnKeyDown

protected override void OnKeyDown(KeyEventArgs e)

No summary in the source yet.

OnLinksChanged

protected virtual void OnLinksChanged(EventArgs e)

Raises LinksChanged.

e
Empty event data.

OnLinksChanging

protected virtual void OnLinksChanging(LinksChangingEventArgs e)

Raises LinksChanging.

e
The proposed change.

OnLostFocus

protected override void OnLostFocus(EventArgs e)

No summary in the source yet.

OnMouseCaptureChanged

protected override void OnMouseCaptureChanged(EventArgs e)

No summary in the source yet.

OnMouseDoubleClick

protected override void OnMouseDoubleClick(MouseEventArgs e)

No summary in the source yet.

OnMouseDown

protected override void OnMouseDown(MouseEventArgs e)

No summary in the source yet.

OnMouseLeave

protected override void OnMouseLeave(EventArgs e)

No summary in the source yet.

OnMouseMove

protected override void OnMouseMove(MouseEventArgs e)

No summary in the source yet.

OnMouseUp

protected override void OnMouseUp(MouseEventArgs e)

No summary in the source yet.

OnMouseWheel

protected override void OnMouseWheel(MouseEventArgs e)

No summary in the source yet.

OnPaint

protected override void OnPaint(PaintEventArgs e)

No summary in the source yet.

OnResize

protected override void OnResize(EventArgs e)

No summary in the source yet.

OnScheduleChanged

protected virtual void OnScheduleChanged(EventArgs e)

Raises ScheduleChanged.

e
Empty event data.

OnSelectedTaskChanged

protected virtual void OnSelectedTaskChanged(EventArgs e)

Raises SelectedTaskChanged.

e
Empty event data.

OnTaskActivated

protected virtual void OnTaskActivated(TaskEventArgs e)

Raises TaskActivated.

e
The task that was activated.

OnTaskChanged

protected virtual void OnTaskChanged(TaskEventArgs e)

Raises TaskChanged.

e
The task that changed.

OnTaskChanging

protected virtual void OnTaskChanging(TaskChangingEventArgs e)

Raises TaskChanging.

e
The proposed change.

OnTaskToggled

protected virtual void OnTaskToggled(TaskEventArgs e)

Raises TaskToggled.

e
The summary that was opened or closed.

OnZoomChanged

protected virtual void OnZoomChanged(EventArgs e)

Raises ZoomChanged.

e
Empty event data.

Reschedule

public void 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

public override void ResetBackColor()

Returns BackColor to the system window colour.

ScrollToTask

public void ScrollToTask(ProjectTask task)

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

public void ScrollToToday()

Scrolls the timeline so that today is a third of the way across it.

SetExpanded

public void SetExpanded(ProjectTask task, bool expanded)

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

protected override Size DefaultSize

The size the chart is given when it is first placed on a form: room for the task list and a few weeks.

ZoomIn

public void ZoomIn()

Shows less time in more detail: one step finer, stopping at Day.

ZoomOut

public void ZoomOut()

Shows more time in less detail: one step coarser, stopping at Year.

ZoomToFit

public void 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

public event EventHandler LinksChanged

Raised after links the reader added or removed have been applied to Links.

LinksChanging

public event EventHandler<LinksChangingEventArgs> 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

public event EventHandler 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

public event EventHandler SelectedTaskChanged

Raised when SelectedTask changes.

TaskActivated

public event EventHandler<TaskEventArgs> TaskActivated

Raised when the reader double-clicks a task, or presses Enter or Space on its row.

TaskChanged

public event EventHandler<TaskEventArgs> TaskChanged

Raised after a change the reader made has been applied to a task.

TaskChanging

public event EventHandler<TaskChangingEventArgs> 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

public event EventHandler<TaskEventArgs> TaskToggled

Raised when a summary task is opened or closed.

ZoomChanged

public event EventHandler ZoomChanged

Raised when Zoom changes.