Click here to Skip to main content
15,065,644 members
Articles / Desktop Programming / Windows Forms
Posted 11 Sep 2015


28 bookmarked

C# Winform Gantt Chart

Rate me:
Please Sign up or sign in to vote.
4.62/5 (16 votes)
11 Sep 2015CPOL
C# Gantt Chart For Winforms


I have been needing an easy Gantt Chart for work and found there are almost no examples out there for C# and Winforms, but I found a good one in Visual Basic and even though I don't write in Visual Basic, I decided to convert it to C#.


I found Adagio.81's Gantt Chart posted on October 2, 2008 and started there. You can see it at Gantt-Chart. This Gantt Chart has all the same features of Adagio81's Gantt Chart but I did fix a few little things and I updated the bar's values after a bar is moved and you can see the new values when you hover over in the tool tip.

Image 1

Using the Code

I add my code in the Form1.cs. There are three examples in Load and you have to hook up your events there also.

//first Gantt Chart

ganttChart1 = new GanttChart();
ganttChart1.AllowChange = false;
ganttChart1.Dock = DockStyle.Fill;

ganttChart1.FromDate = new DateTime(2015, 12, 12, 0, 0, 0);
ganttChart1.ToDate = new DateTime(2015, 12, 24, 0, 0, 0);
tableLayoutPanel1.Controls.Add(ganttChart1, 0, 1);

ganttChart1.MouseMove += new MouseEventHandler(ganttChart1.GanttChart_MouseMove);
ganttChart1.MouseMove += new MouseEventHandler(GanttChart1_MouseMove);
ganttChart1.MouseDragged += new MouseEventHandler(ganttChart1.GanttChart_MouseDragged);
ganttChart1.MouseLeave += new EventHandler(ganttChart1.GanttChart_MouseLeave);
ganttChart1.ContextMenuStrip = ContextMenuGanttChart1;

List<BarInformation> lst1 = new List<BarInformation>();

lst1.Add(new BarInformation("Row 1", new DateTime(2015, 12, 12), 
	new DateTime(2015, 12, 16), Color.Aqua, Color.Khaki, 0));

lst1.Add(new BarInformation("Row 2", new DateTime(2015, 12, 13), 
	new DateTime(2015, 12, 20), Color.AliceBlue, Color.Khaki, 1));

lst1.Add(new BarInformation("Row 3", new DateTime(2015, 12, 14), 
	new DateTime(2015, 12, 24), Color.Violet, Color.Khaki, 2));

lst1.Add(new BarInformation("Row 2", new DateTime(2015, 12, 21), 
	new DateTime(2015, 12, 22, 12, 0, 0), Color.Yellow, Color.Khaki, 1));

lst1.Add(new BarInformation("Row 1", new DateTime(2015, 12, 17), 
	new DateTime(2015, 12, 24), Color.LawnGreen, Color.Khaki, 0));

foreach (BarInformation bar in lst1)
    (bar.RowText, bar, bar.FromTime, bar.ToTime, bar.Color, bar.HoverColor, bar.Index);


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Systems Engineer
United States United States
I Graduated with a Computer Information Science Degree in 1990 and have been working developing systems since then.

I started in COBOL, moved to PROGRESS, did a little RPG, then moved on to Mobile apps and desktop applications.

It's been a great journey Smile | :)

Comments and Discussions

BugVertical Scroll Pin
Member 1494594327-Sep-20 1:54
MemberMember 1494594327-Sep-20 1:54 
Questionopen header date by horizontal scroll bar Pin
Member 148557128-Jun-20 8:55
MemberMember 148557128-Jun-20 8:55 
Praisegood code Pin
Member 1209596529-Oct-18 20:12
MemberMember 1209596529-Oct-18 20:12 
Questionthanks your shared Pin
Member 138945561-Jul-18 20:13
MemberMember 138945561-Jul-18 20:13 
Questionis it possible to print? Pin
Hosam Alaa8-Jun-18 12:55
MemberHosam Alaa8-Jun-18 12:55 
QuestionGannt Chart component how to use in existing project ? Pin
Member 1367295222-Feb-18 23:00
MemberMember 1367295222-Feb-18 23:00 
Generalthank you Pin
Ali Omoum1-Jan-18 8:15
MemberAli Omoum1-Jan-18 8:15 
QuestionText in bar, horizontal scroll bar, hover text Pin
Member 132898793-Jul-17 21:05
MemberMember 132898793-Jul-17 21:05 
QuestionDay view Pin
jmad_197112-Apr-17 4:11
Memberjmad_197112-Apr-17 4:11 
QuestionVS 2015 crashes Pin
muharrem15-Feb-17 2:02
Membermuharrem15-Feb-17 2:02 
QuestionGitHub Pin
Crimdon27-Oct-16 3:08
MemberCrimdon27-Oct-16 3:08 
AnswerRe: GitHub Pin
Member 786566117-May-18 18:40
MemberMember 786566117-May-18 18:40 
QuestionHow do i add additional segment to existing bar with some separation base on stopwatch time? Pin
Member 124349387-Sep-16 20:31
MemberMember 124349387-Sep-16 20:31 
QuestionGantt Chart C# Pin
Member 1249098629-Apr-16 3:13
MemberMember 1249098629-Apr-16 3:13 
Questionhorizontal scroll bar Pin
billcodes23-Mar-16 0:13
Memberbillcodes23-Mar-16 0:13 
how to add horizontal scroll bar?
AnswerRe: horizontal scroll bar Pin
Member 1226777916-Jun-16 22:16
MemberMember 1226777916-Jun-16 22:16 
Questionextend the bar till the end of todate? Pin Pin
billcodes21-Mar-16 3:33
Memberbillcodes21-Mar-16 3:33 
QuestionExist the option for drag drop for bar of the gantt? Pin
Besaleel M. Vieira17-Dec-15 1:50
MemberBesaleel M. Vieira17-Dec-15 1:50 
QuestionNice Article Pin
Santhakumar Munuswamy @ Chennai11-Sep-15 22:16
professionalSanthakumar Munuswamy @ Chennai11-Sep-15 22:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.