Creating a Gantt Chart in VB.NET: 7 Clear Steps Explained
Building a Gantt chart in VB.NET can feel tricky when you need to turn task dates into a clear, working timeline. A few misplaced pixels can make bars confusing, while missing dates or overlapping tasks can leave your chart hard to read.
But here's the truth: you can create a useful chart with Windows Forms and built-in drawing tools. You do not need a third-party chart package for a basic schedule. In seven steps, you’ll define tasks, map dates to screen coordinates, draw task bars, and show the result in a form. I’ll also explain what to change when your schedule grows beyond one screen, so your first version can become a practical project view.
How to Create a Gantt Chart in VB.NET: 7 Steps
The quickest approach is to create a Windows Forms control that draws a task list and timeline in its OnPaint method. This example uses VB.NET and GDI+ to display task names, dates, gridlines, and bars.
- Create a Windows Forms project. In Visual Studio, start a VB.NET Windows Forms project and add a form named
MainForm. The example uses built-in Windows Forms and drawing classes. - Define a task model. Each task needs a name, a start date, and an end date. Add this class to your project:
Public Class GanttTask
Public Property Name As String
Public Property StartDate As DateTime
Public Property EndDate As DateTime
End Class
- Create a custom chart control. Add a class named
GanttChartControl. It inherits fromControland keeps a list of tasks to draw.
Imports System.Drawing
Imports System.Windows.Forms
Public Class GanttChartControl
Inherits Control
Public Property Tasks As List(Of GanttTask)
Public Sub New()
Tasks = New List(Of GanttTask)()
DoubleBuffered = True
BackColor = Color.White
ForeColor = Color.Black
Font = New Font("Segoe UI", 9.0F)
End Sub
End Class
DoubleBuffered reduces flicker when the control repaints. The task list gives the control the information it needs to draw each row.
- Calculate the chart’s date range. Override
OnPaint, then find the earliest start date and latest end date. The number of days in that range determines how wide each day appears.
Protected Overrides Sub OnPaint(e As PaintEventArgs)
MyBase.OnPaint(e)
If Tasks Is Nothing OrElse Tasks.Count = 0 Then
e.Graphics.DrawString("Add tasks to display the schedule.",
Font, Brushes.Gray, 10, 10)
Return
End If
Dim firstDate As DateTime = Tasks(0).StartDate.Date
Dim lastDate As DateTime = Tasks(0).EndDate.Date
For Each task As GanttTask In Tasks
If task.StartDate.Date < firstDate Then
firstDate = task.StartDate.Date
End If
If task.EndDate.Date > lastDate Then
lastDate = task.EndDate.Date
End If
Next
Dim totalDays As Integer = Math.Max(1, (lastDate - firstDate).Days + 1)
Dim labelWidth As Integer = 150
Dim headerHeight As Integer = 30
Dim rowHeight As Integer = 34
Dim chartWidth As Single =
Math.Max(1, ClientSize.Width - labelWidth - 10)
Dim dayWidth As Single = chartWidth / totalDays
' Drawing code continues below.
End Sub
The start and end dates are inclusive, so a task lasting one day still gets a visible bar. The chart width is divided across the full schedule.
- Draw the timeline and task bars. Replace the comment at the end of
OnPaintwith this drawing code. It labels the task rows, adds daily gridlines, and draws each task as a colored bar.
Dim g As Graphics = e.Graphics
Dim gridPen As New Pen(Color.LightGray)
Dim barBrush As New SolidBrush(Color.SteelBlue)
For dayOffset As Integer = 0 To totalDays - 1
Dim x As Single = labelWidth + dayOffset * dayWidth
g.DrawLine(gridPen, x, headerHeight,
x, headerHeight + Tasks.Count * rowHeight)
If dayOffset Mod 7 = 0 Then
Dim tickDate As DateTime = firstDate.AddDays(dayOffset)
g.DrawString(tickDate.ToString("MMM d"),
Font, Brushes.Black, x + 2, 6)
End If
Next
For row As Integer = 0 To Tasks.Count - 1
Dim task As GanttTask = Tasks(row)
Dim y As Single = headerHeight + row * rowHeight
g.DrawString(task.Name, Font, Brushes.Black, 6, y + 7)
Dim startOffset As Integer = (task.StartDate.Date - firstDate).Days
Dim endOffset As Integer = (task.EndDate.Date - firstDate).Days + 1
Dim barX As Single = labelWidth + startOffset * dayWidth
Dim barY As Single = y + 7
Dim barWidth As Single = Math.Max(dayWidth, (endOffset - startOffset) * dayWidth)
g.FillRectangle(barBrush, barX, barY, barWidth, 20)
g.DrawLine(gridPen, 0, y + rowHeight,
ClientSize.Width, y + rowHeight)
Next
gridPen.Dispose()
barBrush.Dispose()
The weekly labels keep the header from becoming crowded. Daily gridlines still help you estimate task duration. For a very long schedule, consider drawing gridlines weekly instead.
- Add the control to your form and create sample tasks. Add this code to the form’s load event. Adjust the task names and dates to match your schedule.
Public Class MainForm
Private gantt As New GanttChartControl()
Private Sub MainForm_Load(sender As Object,
e As EventArgs) Handles MyBase.Load
gantt.Dock = DockStyle.Fill
Controls.Add(gantt)
gantt.Tasks.Add(New GanttTask With {
.Name = "Plan project",
.StartDate = New DateTime(2025, 4, 1),
.EndDate = New DateTime(2025, 4, 4)
})
gantt.Tasks.Add(New GanttTask With {
.Name = "Build prototype",
.StartDate = New DateTime(2025, 4, 3),
.EndDate = New DateTime(2025, 4, 10)
})
gantt.Tasks.Add(New GanttTask With {
.Name = "Test release",
.StartDate = New DateTime(2025, 4, 11),
.EndDate = New DateTime(2025, 4, 15)
})
gantt.Invalidate()
End Sub
End Class
These dates deliberately overlap. You can see how one task’s bar continues while another begins, which is useful for spotting parallel work.
- Run the project and refine the display. Check that the dates fit, labels are readable, and bars line up with the correct days. Then adjust row height, colors, or date labels to suit your team.
Here's why: the chart’s drawing logic depends on the control’s available width. If you resize the form, the number of pixels per day changes. For larger schedules, add scrolling or show a shorter date window rather than squeezing every day onto one screen.
How the Date-to-Pixel Calculation Works
A Gantt chart converts calendar time into horizontal position. If the first visible date is April 1, a task starting April 4 begins three day-units from the left edge of the timeline.
The example calculates that offset with (task.StartDate.Date - firstDate).Days. It then multiplies the offset by dayWidth to find the bar’s horizontal coordinate.
The end date needs special handling. Adding one day to its offset makes the end date inclusive. A task from April 1 through April 3 therefore spans three day-units, rather than stopping at the start of April 3.
You might be wondering: what happens if tasks have different start and end dates? The chart sets its visible range from the earliest start to the latest end. That way, every task fits within the same timeline.
Make the Chart Easier to Read and Maintain
Start with the information people need to act. Task names belong beside the bars, while dates belong in the timeline header. If names are long, widen the label area or shorten the displayed wording.
For example, a release schedule with 90 days of work may become too dense when every day gets a label. Keep daily gridlines if they help, but show a date label every week or month. You can also change the date window with navigation buttons.
But here's the truth: the sample control is a starting point, not a complete scheduling system. It does not include dependency arrows, drag-to-reschedule behavior, weekends, milestones, or automatic scrolling. Add those features only when your project needs them.
Keep drawing code separate from task editing. For instance, update a task’s dates in a form or service, then call gantt.Invalidate(). That asks Windows Forms to repaint the chart using the revised values.
Test Edge Cases Before Relying on the Timeline
A chart can look correct with three sample tasks and still fail on real schedules. Test tasks that begin on the same day, last one day, overlap, and start or end at the visible range’s boundary.
Also check invalid date ranges. If a task ends before it starts, the displayed bar can have an incorrect width. Reject that task when it is entered, or display a clear validation message before refreshing the chart.
For example, a simple check can stop an invalid task from being added:
If newTask.EndDate.Date < newTask.StartDate.Date Then
MessageBox.Show("The end date must be on or after the start date.")
Return
End If
Test the form at different window sizes, too. A 30-day view may be clear at full width but cramped in a narrow window. That cause-and-effect relationship is why zoom controls and scrolling matter as schedules expand.
When a Custom VB.NET Chart Is the Right Fit
A custom chart works well when you need a focused visual inside a VB.NET desktop application. You control the appearance and can connect the display to your own task-entry screens.
It takes more effort when people need to edit schedules together, report progress, or coordinate work across teams. You would need to build and maintain those functions alongside the chart, including permissions, updates, and status tracking.
Let me explain: the chart answers “when is this task scheduled?” A project workflow also needs to answer who owns it, what blocks it, and whether its status changed. Keep the custom control for a focused application view; consider a project platform when shared planning becomes the bigger need.
Project Coordination Beyond a Custom Chart: ONES.com
Value proposition: ONES.com brings project management and knowledge management together in one platform, while ONES Project and ONES Wiki are sold separately. For a team building a VB.NET Gantt view, it can support shared planning and project coordination around the application’s custom chart.

A custom Gantt control handles a visual timeline. ONES.com is relevant when your team also needs to organize work, track progress, and keep project knowledge accessible. ONES Project is the project management product and a Jira alternative; ONES Wiki is the knowledge management product and a Confluence alternative.
Core Capabilities
- Scattered task ownership → ONES Project task management → organize project work in shared workflows instead of relying only on a chart inside one desktop application.
- Changing project processes → Custom workflows and fields → reflect the way your team handles task types, statuses, and project details.
- Unclear delivery progress → Built-in reporting → give project leads a way to review status without building every report into the VB.NET interface.
- Iteration planning needs → Sprint management → coordinate sprint work alongside the broader schedule.
- Repeated manual updates → Automation → reduce repetitive workflow actions through configured rules.
- Existing Jira habits → Jira-compatible workflows → help teams preserve familiar ways of working while evaluating a Jira alternative.
- Project guidance spread across tools → ONES Wiki knowledge management → keep team knowledge alongside project activity when both products suit the workflow.
- Plugin-heavy customization → Native capabilities and feature parity → reduce reliance on add-ons while retaining parity between cloud and self-hosted versions.
Application Scenarios
A small VB.NET development team can use its custom Gantt chart for a desktop schedule while coordinating tasks and sprint work in ONES Project. That split keeps chart rendering in the application and shared work tracking in the project platform.
A team with deployment restrictions can evaluate ONES.com’s Cloud, On-Premise, Private Cloud, and Air-gapped deployment options. It offers a free plan for up to 30 seats, which can help a team assess fit before expanding its use.
ONES.com is a separate project coordination option, not a VB.NET chart library. Choose it when shared workflows matter; keep your custom control when a tailored, in-app timeline is the primary requirement.
Common Challenges and Practical Fixes
- Bars appear one day too short. Treat the end date as inclusive and add one day to the ending offset before calculating the bar width.
- Long schedules become cramped. Show a shorter date range, add horizontal scrolling, or provide zoom levels instead of shrinking every day into a few pixels.
- Task labels run into the timeline. Increase the label area, shorten task names for display, or provide a tooltip with the full name.
- The chart flickers during updates. Keep double buffering enabled and update the task list before calling
Invalidate(), rather than repainting after every small change. - Dates produce misleading bars. Validate that each end date is on or after its start date, and test same-day and overlapping tasks.
Frequently Asked Questions
Can I create a Gantt chart in VB.NET without a third-party library?
Yes. A Windows Forms control can draw a basic Gantt chart with the built-in GDI+ drawing tools shown here. You define the task model, calculate date positions, then draw the timeline and bars in OnPaint. A third-party library may save time if you need advanced interactions, dependency links, or built-in scrolling.
How do I show task dependencies?
First, give each task an identifier and record which task it depends on. Then draw a line or arrow between the bars after drawing the tasks. You will need to decide how to position the connector and avoid obscuring other bars. For many dependencies, use scrolling or zooming so the connector paths remain understandable.
How can I add scrolling to a large chart?
Place the chart inside a scrollable container or implement a custom horizontal viewport. The chart needs to draw a selected date range, while navigation changes that range. Simply shrinking dayWidth to fit every project date can make bars and labels difficult to read, so scrolling or zoom controls usually work better.
How do I make the Gantt chart refresh after a task changes?
Update the task’s dates or name, then call Invalidate() on the chart control. Windows Forms will schedule a repaint, and OnPaint will draw the updated schedule. If you change several tasks together, apply all changes first and invalidate once to avoid unnecessary redraws.
Conclusion
You can create a practical VB.NET Gantt chart by defining a task model, mapping dates to pixels, and drawing rows, gridlines, and bars in a custom Windows Forms control. Start with a few tasks, validate date ranges, and test different schedule lengths before adding advanced features.
The main challenge is keeping the timeline readable as work grows. Add a date window, scrolling, or zooming when a single view becomes crowded. If your needs expand from displaying dates to coordinating shared project work, evaluate whether a project platform such as ONES.com fits alongside your custom application.