0 ratings0% found this document useful (0 votes) 489 views18 pagesC# Winforms Gantt Chart Control - THINK
.NET C# Winforms Gantt Chart Control _ THINK
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
2omn0%6 INET Cit Wirvorms Gantt Chart Coral | THINK.
THINK
that's how i naturally know
.NET C# Winforms Gantt Chart Control
Last Update: September 10, 2014
This blog post is updated for Gantt Chart Control 1.3.
Project Description
The .NET C# Winforms Gantt Chart Control is a class library project hosted on codeplex that provides a quick
way to get a gantt chart up and running for your application
This control was first developed as part of a report writing task. At that time of writing the report, | did not have
at hand a software like Microsoft Project but | still needed to show a gantt chart. Hence | ended up “drawing”
my chart in code as it was the faster alternative than drawing it in, say, Photoshop or PowerPoint as repeated
edit changes were dynamic and fast.
‘As such, this winforms control will be suitable if you just need simple features for a larger application or for
prototyping purposes. Hopefully, I can add more features to the control to make it more robust in time to
come.
Documentation
The doxygen documentation provides a full list of “developer” API you can refer to. However, as a user you only
need to read the following interfaces to see what the user API offers:
* Chart
* ProjectManager
* Task
Code examples are included in the downloads. More code examples will be provided here in due time.
Basic Use Case
public Formi()
Initializeconponents();
// create a project manager
var manager = new ProjectManager();
// create built-in task or use your own derived task
var task = new Task() { Name = "Hello World"; };
ep dhwww jakesee.comine-c-winforms-gant-char-canvall wie2omn0%6 INET Cit Wirvorms Gantt Chart Coral | THINK.
8 // add the task to the manager
9 manager. Add(task) ;
ae // create a chart control
a var chart = new Chart();
2 // initialise the chart with the manager
B chart. Init (manager);
14 // add chart to the form controls collection.
45 ‘this.Controls.add(chart) ;
16
v7 // throughout your own code, call chart.Invalidate()
18 // where you expect updates to the drawn chart,
as 7/ to tell the chart to Paint() itself.
20] }
Task Label Group Slack
Now 9y9z012 ea usiad
TFS SM twit F 6-4 Header?
BarSpacing
Barbleight
Relation
BaiWidth ForefilBackFill (Ow)Line
Features
+ Time unit independant data structure specification
* Chart can be customised in various ways to draw in different time scales, grid size, font, colors and
shapes,
= Single tasks, grouped tasks, sub tasks, precedent tasks, split tasks
* Percentage complete property for each task and group
* Various mouse events for customising advance mouse UI experience directly on the chart.
+ Printing to file
* Set tool
for show/hide during mouseover and mouseout on tasks.
+ Programatically scroll to particular date/time (horizontall) or task (vertically)
+ Shows slack and critical paths
Feature requests and fixes are welcomed through discussion page. Thank you for your contributions.
Mouse Commands
The control comes with a default set of mouse commands for quickly creating and editing the gantt chart.
© Left Click - Select task
ep dhww jakesee.comine-c-winforms-gant-char-canval! 28zorrnots NET Ctr Wirforms Gar Chart Contra | THINK
+ SHIFT + Left Click - Select multiple tasks
+ Left Mouse Drag - Change task starting point
* Right Mouse Drag - Change task duration
+ Middle Mouse Drag - Change task complete percentage
+ Left Double Click - Toggle collaspe on task group
* Right Double Click - Split task into task parts
* Left Mouse Dragdrop onto another task - Group dragged task under dropped task
+ Right Mouse Dragdrop onto another task part— Join task parts
* SHIFT + Left Mouse Dragdrop onto another task - Make dragged task a successor of dropped task
+ ALT + Left Mouse Dragdrop onto another task - Ungroup dragged task from dropped task / Rernove
successor - predecessor relationship
‘+ SHIFT + Left Mouse Dragdrop - Reorder tasks
+ SHIFT + Middle Click on task - Create new task under the clicked task
+ ALT + Middle Click - Delete Task
‘These commands can be modifed by using various code contructs e.g. event listeners or inheritance (method
overrides),
Setup / Installation
GanttChart does not require any dependencies. Simply add the DLL to your project, or add the GanttChart
project to your solution and add the reference to the project,
Object Classes
‘The API exposes 3 main classes, Project, Chart and Task
* The Project is where the data i.e. Tasks and their relationships are specified.
+ The Chart is a UserControl responsible for visualising the Project, in this case, presents it as a Gantt Chart.
+ The Task is a data structure caching schedule information. A Task with sub task is a task group,
ProjectManager
‘The ProjectManager class provides logic for managing Tasks and provides analytic information regarding the
project schedule such as Critical Paths (Although that’s the only thing worth mentioning at the moment. Will
add more in the future). ProjectManager is the logic layer and you can design UI controls on top of Project for
visualisation, for example a Work Breakdown Structure, Histogram etc. The Gantt Chart control is one such Ul
that is currently in this project.
Chart
The Chart class is responsible for turning the data in Project into graphics for visualisation and for user to
graphically interact with it, thereby performing edits on the underlying Project data. It is also our objective to
design Chart in a way where customisation of its look and feel should be as simple as possible, Hence Chart,
provides events both for input (mouse and keyboard) and paint events in which users can listen to and plug in
code as approperiate. For a complete modification, itis also possible to derive a specialised class from Chart
and implement your own custom methods,
ep dhww jakesee.comine-c-winforms-gant-char-canval! anezorrnots INET C#Winforms Gant Chart Control | THINK,
Task
‘The Task resides in ProjectManager, in associative structures representing their relationships with each other
and their resources. Internally, ProjectManager calculates and caches schedule information in Task for chart t
lookup and draw. Custom Tasks can be dervied and added to ProjectManager to store your own custom
application logic or allow other controls such as PropertyGrid to manipulate its properties.
Custom Drawing Coordinate System
If you are extending the control for more customise drawing, either by listening to paint events or creating a
derived chart and overriding paint methods, this section is for you, as you may find that things are not drawing
at the location you tell itto.
‘The display of drawings (Tasks, headers, columns etc.) on the Control is treated in a specialised manner to
overcome Winforms controls size limits and also to simplify the moving of drawing from the application to print
and other devices.
Device (UserControl, PrintDocument), etc
‘The entire surface of the chart is in an imaginary area where the top left corner is the origin representing the
ProjectManager.Start date. All the task have time schedules relative to the start date and resides on the
imaginary surface of the chart. All the tasks when drawn, are drawn onto this coordinate space called chart-
coordinates,
‘A Viewport hovers above the chart and moves about in this chart coordinates. The Viewport captures all the
images of tasks and relations directly under it and within its boundary, known as a Viewport Rectangle.
Everything else is culled away. It then calculates the Header information and columns that should appear at the
top of its Rectangle and sticks it there.
ep dhww jakesee.comine-c-winforms-gant-char-canval! a8zorrnots INET C#Winforms Gant Chart Control | THINK,
In the next step, the Viewport projects and squeezes all of its contents onto a device, such as the Winforms
control or a piece of printing paper, thereby producing the image you see on the device. The device has its own
coordinate system where in the case of the winforms control, the top left is (0, 0) regardless of the Viewport
location in chart-coordinate space. Hence, when the mouse reports its location on the device, the mouse
device-coordinates cannot be used directly, to locate items in the chart-coordinate space,
In the normal use case, all these coordinate conversions would have been taken care of, and all you need to do
is to specify points and rectangles in chart-coordinate space, with the only exception of drawing billboards.
Once Chart.BeginBillboardModet) is called, all points and rectangles will be drawn in device-coordinate space
Until Chart.EndBillboardModel) is called
7 Comments Sort by Oldest
Add a comment.
Jake See - Singapore
Like “Reply «9 2: Feb 17,2013 5:39am
is it possible to use diffrent colors for every task?
Thanks
Like “Reply May 17, 2013 12:20pm
Py Jake See - Singapore
Hi Bilal, just noticed your message. | believe you can listen to the
Chart.PaintTask event and provide the TaskFormat in the argument.
Like - Reply -Jun 7, 2013 4:40am
iu Bilal Tatar Istanbul Universitesi Ogrencileri
‘Thank you so much Jake, following your advice i resolved the problem. . Due
to our prime minister who is a dictator wannabe i couldn't answer you early.
‘Thanks again for your kind answer.
Like - Reply Jun 14,2013 11:31am
Ozgur E Oner : Kocaeli University
Hello Jake,
how can | convert it to paf?
Like - Reply: Jul 29,2013 11:33am
Saadet Oguzsimsaroglu - I..M.M.A GALATASARAY MUHENDISLIK
YUKSEK OKULU
ps jokesee comine-cowifors-gat-char-conl! 582omn0%6 INET Cit Wirvorms Gantt Chart Coral | THINK.
bunu da begenmem lazim miydi bilemedim
Like “Reply - Jul 29, 2018 8:53pm
a Jake See - Singapore
Hello, there is no built in conversion to PDF. You can download a third party
POF driver example, http:/ien.pdf24.org/ and then you can print to PDF from
the print dialog.
Like -Reply- Aug 11,2013 12:01am
Du Ben - Sr. Solution Architect at HP,BAS China
Is it possible to capture a task’s old/new Start/End date whenever they are modified?
Like “Reply Aug 9, 2013 7:58pm
Jake See + Singapore
Not sure if| understand you correctly, since you need to create the Ul and
write the code to change the dates, you can also insert your own code to
execute actions before calling the ganttchart code to modify dates.
Like “Reply: Aug 11,2013 12:05am Edited
Costardi Roberto
hi very good your job!
do you think it will possible to have a "TimeScaleDisplay" and "TimeScale” for hour?
Thank you
Like Reply: Aug 14,2013 10:35am
Daniele Urbanelli
Currently, the task starts/ends at mid-day, and this can lead to confusion.
Can start the task from the starts/ends line of the day?
Like “Reply Mar 16, 2014 11:45pm
Stephan Eibl
A question from a more less experienced c# user. How could | start the gantt chart DLL
from the main after setting up all references from the main code .. ? Many thanks.
Like “Reply Mar 8, 2016 6:24am
1 Facebook Comments Plugin
46 thoughts on ".NET C# Winforms Gantt Chart Control”
Juan Gabriel Castillo
September 1, 2012 at 2:15 am
\ bro,.. nice your Gant Chart
| programming a hotel system and i want to schedule the room occupation.
Did you have the control documentation?
ep dhww jakesee.comine-c-winforms-gant-char-canval! ane2omn0%6 INET Cit Wirvorms Gantt Chart Coral | THINK.
iwant understand it better
Regards
Jake Cos)
September 1, 2012 at 1:26 pm
HiJuan,
‘Thanks for your interest. | have generated a doxygen documentation at http://jakesee.corn/docs/ganttchart
and updated my blog post above,
‘As a user of the API, you really only need to look at the Chart, ProjectManager and Task classes.
Hope you will find some use in this early stage of development,
Oliver
February 4, 2013 at 12:51 am
Hey,
I'd like to use this Gantt Chart in my Programm to show some TV EPG data @
But i just find TimeScale.Day or Week is it possible to set the TimeScale to Hour or Minute ?
Thx
sD
whee Jake [saute]
February 4, 2013 at 912 am
Hi Oliver, thanks for your interest. Unfortunately, | created it for a project that spanned several years, so
support for hours and minutes was not built into It.
ep dhww jakesee.comine-c-winforms-gant-char-canval! 782omn0%6 INET Cit Wirvorms Gantt Chart Coral | THINK.
Josh
February 7, 2013 at 530 am
| am saving the data from the chart on program exit, and refilling the chart on startup. How can | get the tooltip
for a task so that it can be saved?
Geo Jake [sure]
February 17, 2013 at 8:40 pm
HiJosh,
Sorry for not replying earlier. The Chart class has a SetTooITip() but does not have a GetTooITip0. The
philosophy is to use Chart class as a U-only class and does not store data for retrieval later.
Ideally, you should track your own tooltip in your own custom ProjectManager class by deriving from it, or, a
custom Task class that has the tooltip as one of the property.
With that said, you can add your own GetToo!Tip( function quite easily i you download the source and
navigate to SetToo!Tip to see how it is done. I's just returning the value from a hash container. Also, | have now
added this to the latest source code,
Rick
February 17, 2013 at 2:05 am
You did a great job and | enjoyed reading the code.
w9fes Jake Cat)
February 17, 2073 at 8:40 pm
Hi RickC, Thank you! Glad you liked it,
ep dhww jakesee.comine-c-winforms-gant-char-canval!
ate2omn0%6 INET Cit Wirvorms Gantt Chart Coral | THINK.
Jake See
February 17, 2013 at 1:39 pm
New facebook comments for my blog!
Josh
February 23, 20 am
| actually did end up creating a custom task class to help me with this. It also allowed me to store more
information about the task which | needed to be able to do to keep the task unique and allow me to update as.
needed. Thanks for your reply though, and this has been very helpful
Sergio
March 13,2013 at 3:44 prn
Hi Jake!
Congratulations for the Gantt Project, it’s very nice and complete Gantt chart.
| would use your chart for a planning App, but I need to implement zoom on the chart...
Have you planned the possibility of rake zoom (with the mouse scroll for example) to the chart? How do you
think that it will be more easy to implement?
| forget to tell you that | managed to run the gantt chart in a WPF application!
Congratulations again for your job!
Bilal Tatar
May 17, 2013 at 7:20pm
this realy awesome gantt,
ep dhww jakesee.comine-c-winforms-gant-char-canval! ane2omn0%6 INET Cit Wirvorms Gantt Chart Coral | THINK.
is it possible to use diffrent colors for every task?
Thanks
‘Smael
June 7, 2013 at 2:33 am
Hi, congratulations at project.
My question, How I insert a task who I started and I finished in the some day?
Jake See
June 7, 2013 at 11:40 am
Hi Bilal, just noticed your message. | believe you can listen to the Chart.PaintTask event and provide the
‘TaskFormat in the argument.
Bilal Tatar
June 14, 2013 at 6:31 pm
Thank you so much Jake, following your advice i resolved the problem. . Due to our prime minister who is a
dictator wannabe i couldn't answer you early. Thanks again for your kind answer.
Smael
June 24, 2013 at 10:38 pm
Hi, sorry, | meant to start and finish the job the same day.
fee Jake (Festautor)
June 25, 2013 at 9:06 am
ep dhww jakesee.comine-c-winforms-gant-char-canval!
1082omn0%6 INET Cit Wirvorms Gantt Chart Coral | THINK.
Hello Smael,
‘The smallest unit for this control is 1 day hence it cannot represent accurately a fraction of a day. This is a
limitation of this control
The best you can do is if itis less than a day, then you round up to 1 day, or just omit it entirely.
SyBar'g Baris
July 29, 2073 at §:25 pm
HiJake,
How can I save as pdf?
Ozgirr E. Oner
July 28, 2013 at 6:33 pm
Hello Jake,
how can | convertit to pdf?
Saadet Oguzsimsaroglu
July 30, 2013 at 3:53 am
bunu da begenmem lazim miydi bilemedim @
BY Pawel). wal
ESME auguse 9, 2073 2¢ 11:09 pm
Hi Jake,
Your control is great! | have one question, however, and | can‘t figure the answer by looking at the docs. Can
ep dhww jakesee.comine-c-winforms-gant-char-canval!
wwe2omn0%6 INET Cit Wirvorms Gantt Chart Coral | THINK.
the control be cut off at a particular date?
| only want to show a week's worth of tasks at once. Do I need to physically scale the control so that only a
week is visible?
Jake
‘August 11, 2073 at 2:16 pm
Hi Pawel,
Currently, the control cannot set a cut-off date for viewing at the moment, It will scroll horizontally to the latest
date the last task will end,
have not tried it yet, but maybe if you subscribe to the scroll events, you can determine whether the user has
scrolled more than 1 week's task and then disable the scrolling
Du Ben
‘August 10, 2013 at 2:58 am
Is it possible to capture a task's old/new Start/End date whenever they are modified?
Jake See
‘August 11, 2073 at 7:07 am.
Hello, there is no builtin conversion to PDF. You can download a third party POF driver example,
http://en.pdf24.org/ and then you can print to PDF from the print dialog.
Jake See
August 11, 2013 at 7:04 am
Not sure if | understand you correctly, since you need to create the Ul and write the code to change the dates,
ep dhww jakesee.comine-c-winforms-gant-char-canval! sae2omn0%6 INET Cit Wirvorms Gantt Chart Coral | THINK.
you can also insert your own code to execute actions before calling the ganttchart code to modify dates.
Pawet J. Wal
‘August 11, 2013 at 9:37 pm
HiJake,
| see. Ill have to try handling scroll events then. Thank you for the prompt response. @
Leigh
August 14, 2013 at 6:07 pm
Hi Jake,
‘Thank you for sharing your code with us. It's very generous of you!
Is it possible to set a Tasks start and end date instead of using SetDuration0? | see that methods Start() and
End() will only accept integer (i.e. days).
Itmakes more sense to work with dates than days, especially when your data is stored in the database.
Jake Cave)
‘August 15, 2013 at 12:23 am
Hi Leigh, the control was designed to take relative periods as parameters instead of dates so that it does the
arithmetics for drawing faster. The Task.Start and Task End accepts an integer relative to the
ProjectManager.Start DateTime value, hence you can write a separate function that does the calculation for
you. e.g, void SetTaskDateTime(Task t, DateTime start, DateTime end)
http://stackoverflow.com/questions/5177002/how-to-subtract-a-datetime-from-another-datetime
Costardi Roberto
‘August 14, 2013 at 5:35 pm
ep dhww jakesee.comine-c-winforms-gant-char-canval! v82or20%6 INET C#Winforms Gant Chart Control | THINK,
hivery good your job!
do you think it will possible to have a "TimeScaleDisplay" and “TimeScale” for hour?
Thank you
Oriol
December 17, 2013 at 7:38 pm
Hello Jake,
congratulations on the Gantt Chart, very useful,
would you be so kind to post an example on task color change
trying to use the Chart. PaintTask event but not get the desired output
much appreciated
ifs Jake Conte)
December 17, 2013 at 9:56 pm
Hi Oriol, thank you for trying out my winforms control
This event handler for PaintTask uses a gradient brush to paint the task.
void _mChart_PaintTask(object sender, TaskPaintEventArgs e)
«
var format = e.Format;
format.BackFill = new System.Drawing.Drawing2D.LinearGradientBrush(e. Rectangle, Color.PeachPuff,
Color.PaleGreen, 459);
e.Format = format;
y
Daniele Urbanelli
March 17, 2014 at 6:45 am
Currently, the task starts/ends at mid-day, and this can lead to confusion
ps jokeseo comine-cowifors-gant-char-conl! wie2omn0%6 INET Cit Wirvorms Gantt Chart Coral | THINK.
Can start the task from the starts/ends line of the day?
Bruno
December 30, 2014 at 2:17 am
hello Daniele, i think this may help you
(float)task.Start * this.BarWidth /*+ this.BarWidth / 2*/
Tobias
December 30, 2015 at 5:29 pm
Hello Bruno,
| found your reply, maybe you can tell me where to use the code you mentioned? I can not find out where to
put in the code to get it running, Thank you!
Tobias
karl
June 11, 2014 at:
is there an option to draw horizontal row lines ?
iy Jake FFoxaurer}
June 11, 2074 at 10:43 pm
Hi Karl, not sure what you mean by horizontal row lines, but there is not intended drawing library. You will have
to edit the source if you want to change the graphics drastically.
ep dhww jakesee.comine-c-winforms-gant-char-canval! 1982omn0%6 INET Cit Wirvorms Gantt Chart Coral | THINK.
Sylvain
August 23, 2014 at 2:39 am
Great Control,
Ihave done a few modification to be able to show hour precision.
Thanks,
Sylvain
p.s. I guess karl meant the vertical line
Geo Jake [Fs uhor)
‘August 23, 2014 at 11 arn
Hi Sylvain, thanks for your feedback, Glad that the control helped you. If you woul like to share your
modifications, we can add you as a contributor and merge the changes if appropriate. Thanks,
Khirendra
December 11, 2014 at 6:16 pm
Is is possible to connect to sql database and produce chart accordingly and other way around?
Arduvast Gundar
February 17, 2016 at 10:10 pm
Using LINQ to SQL it is possible (I've been doing so, using MS-Visual Studio 2015 and C# and it works well,
though it can take some effort to get the data you want in the form you need).
Pingback: Web Gantt Chart Open Source | Technology Documents
ep dhww jakesee.comine-c-winforms-gant-char-canval! swe2omn0%6 INET Cit Wirvorms Gantt Chart Coral | THINK.
Pingback: Web Gantt Chart Control | Technology Documents
dangbaoduy
016 at 12:46 pm
January 20,
‘Thanks, your project's very useful for me
Arduvast Gundar
February 16, 2016 at 8:01 pm
Ive been looking for something like this,
First off, what | like about this gantt Chart implementation:
+ Itis well documented - even members that aren't relevant to the end user, which makes modifying it a lot
easier.
+ itis easy to use, Calling only a few, non-cryptic, uncomplicated methods gets me right where | want to be.
Nevertheless, it doesn't lose its versatility in the process.
+ it's free and it's easy and legal to modify it or add features, especially due to its well written, almost self
explainatory code,
| checked the alternatives and had a hard time finding something like it (especially on the versatile, well
documented AP! side of things), Thumbs up @ .
However, there is one thing | sorely miss: Milestones or items that belong to a Point in time but don't have a
Duration, marked by an different shape, something like triangles, Diamond shapes, stars or something like
that. | will have to add those myself,
‘And | would like to have multiple Items grouped in one timeline (horizontally, not stacked vertically, provided
they don't overlap, adding a timeline class would probably be the way to do that). But | guess I can live with the
Status quo for the Moment, going with Groups (love those, by the way) just now and adress it later, when Ive
got more time.
Kind regards,
Arduvast
Legal disclaimer-
Information provided in this form are provided only for purposes of Monitoring comments and Posts and
making answers to such Posts/comments possible, The provided information may not be used for market
Analysis, advertisement, spam or purposes that could be considered abuse of the information. The author
determines, whether or not an intended use is to be considered abuse. When in doubt, don't use the
inform,
tion,
ep dhww jakesee.comine-c-winforms-gant-char-canval! wie2omn0%6 INET Cit Wirvorms Gantt Chart Coral | THINK.
whee Jake See [ox ao)
February 17, 2076 at 10:54 pm.
‘Thanks Arduvast for the review. Really appreciate your time for writing, People like you keeps the open source
community alive.
Stephan Eibl
March 8 2016 at 2:24 pm
A question from a more less experienced c# user. How could | start the gantt chart DLL from the main after
setting up all references from the main code ..? Many thanks.
ep dhww jakesee.comine-c-winforms-gant-char-canval! swe