ComponentOne GanttView for WinForms
Customizing the Bar Style
GanttView for WinForms Task-Based Help > Customizing the Bar Style

To call attention to task bars on a Gantt view, such as a milestone, you can change their color, shape, or pattern to separate them from other bars of a particular type.

You could customize the appearance of all the bar styles or  you could customize the appearance of an individual Gantt bar if you want to highlight a specific task in your plan.

Change the bar style at design time

  1. Right-click on the C1GanttView control and select Edit Bar Styles. The C1GanttView.BarStyles Collection Editor appears.
  2. Click Add to add a bar style to the collection.
  3. Set the BarType to AutoTask.
  4. Set the BarShape to ThickBar.
  5. Set the BarColor to LightSkyBlue.
  6. Click Add to add a bar style to the collection.
  7. Set the BarType to ManualTask.
  8. Set the BarShape to ThickBar.
  9. Set the BarColor to PaleGreen.
  10. Click OK to save and close the C1GanttView.BarStyles Collection Editor.

Change the style of a specific task at design time

  1. Right-click on the control and select Edit Tasks. The C1GanttView.Tasks Collection Editor appears.
  2. Select the task you want to customize from the members list and click on the ellipsis button next to the BarStyles. The C1GanttView.BarStyles Collection Editor appears.
  3. Click Add to add a bar style to the collection.
  4. Set the BarType to AutoTask.
  5. Set the BarShape to TopBar.
  6. Set the StartShape and EndShape to 2.
  7. Set RightText2 to ResourceNames.
  8. Click OK to save and close the C1GanttView.BarStyles Collection Editor.

Change the bar style in code

To change the bar style for all manual tasks programmatically, complete the following:

To write code in Visual Basic

Visual Basic
Copy Code
Private Sub btnChangeBarStyle_Click(sender As Object, e As EventArgs)
       Dim bs As BarStyle = ganttView.GetPredefinedBarStyle(BarType.ManualTask)
       bs.BarColor = Color.LightCoral
       ganttView.BarStyles.Add(bs)
End Sub

To write code in C#

C#
Copy Code
private void btnChangeBarStyle_Click(object sender, EventArgs e)
{
    BarStyle bs = ganttView.GetPredefinedBarStyle(BarType.ManualTask);
    bs.BarColor = Color.LightCoral;
    ganttView.BarStyles.Add(bs);
}

Change the style of a specific task in code

To change bar style for task3 programmatically, complete the following:

To write code in Visual Basic

Visual Basic
Copy Code
Private Sub btnChangeTaskStyle_Click(sender As Object, e As EventArgs)
       Dim task3 As Task = ganttView.Tasks.Search("Task 3")
       If task3 IsNot Nothing Then
              Dim bs As BarStyle = ganttView.GetPredefinedBarStyle(BarType.ManualTask)
              bs.BarColor = Color.Green
              bs.BarShape = BarShape.MiddleBar
              bs.StartShape = 19
              bs.EndShape = 19
              task3.BarStyles.Add(bs)
       End If
End Sub

To write code in C#

C#
Copy Code
private void btnChangeTaskStyle_Click(object sender, EventArgs e)
{
    Task task3 = ganttView.Tasks.Search("Task 3");
    if (task3 != null)
    {
        BarStyle bs = ganttView.GetPredefinedBarStyle(BarType.ManualTask);
        bs.BarColor = Color.Green;
        bs.BarShape = BarShape.MiddleBar;
        bs.StartShape = 19;
        bs.EndShape = 19;
        task3.BarStyles.Add(bs);
    }
}
See Also