Back to Devexpress

GanttControl.CustomDrawTaskDependency Event

windowsforms-devexpress-dot-xtragantt-dot-ganttcontrol-e2b6f298.md

latest4.9 KB
Original Source

GanttControl.CustomDrawTaskDependency Event

Fires before a task dependency line in the chart area is displayed. Provides access to a drawing surface and allows you to draw the task manually.

Namespace : DevExpress.XtraGantt

Assembly : DevExpress.XtraGantt.v25.2.dll

NuGet Package : DevExpress.Win.Gantt

Declaration

csharp
[DXCategory("Events")]
public event CustomDrawTaskDependencyEventHandler CustomDrawTaskDependency
vb
<DXCategory("Events")>
Public Event CustomDrawTaskDependency As CustomDrawTaskDependencyEventHandler

Event Data

The CustomDrawTaskDependency event's data class is CustomDrawTaskDependencyEventArgs. The following properties provide information specific to this event:

PropertyDescription
AppearanceProvides access to appearance settings that specify the dependency line background color.
CacheProvides access to the drawing surface and a cache of brushes, pens, fonts, and other graphics. Inherited from CustomDrawEventArgs.
HandledGets or sets whether the event is handled and allows you to prevent the control from drawing the visual element in its default appearance. Inherited from CustomDrawEventArgs.
LinesProvides access to the collection of RectangleF structures that specify the processed dependency line.
PredecessorNodeGets the predecessor node.
StateGets the object state: normal, hot tracked, pressed, disabled, or selected.
SuccessorNodeGets the successor node.

The event data class exposes the following methods:

MethodDescription
DefaultDraw()Draws the task dependency line.

Example

The code below shows how to highlight specific tasks and dependencies.

Run Demo: Highlight Tasks and Dependencies

csharp
HashSet<int> tasks = new HashSet<int> { 1, 2, 3, 6, 7, 8, 10, 11, 13 };
ganttControl.CustomDrawTask += (sender, e) => {
    int taskId = Convert.ToInt32(e.Node.GetValue("Id"));
    if(tasks.Contains(taskId)) {
        e.Appearance.BackColor = DXSkinColors.FillColors.Warning;
        e.Appearance.ProgressColor = DXSkinColors.FillColors.Warning;
    }
};
ganttControl.CustomDrawTaskDependency += (sender, e) => {
    int predecessorId = Convert.ToInt32(e.PredecessorNode.GetValue("Id"));
    int successorId = Convert.ToInt32(e.SuccessorNode.GetValue("Id"));
    if(tasks.Contains(predecessorId) && tasks.Contains(successorId)) {
        e.Appearance.BackColor = DXSkinColors.FillColors.Warning;
    }
};
vb
Dim tasks As New HashSet(Of Integer)() From {1, 2, 3, 6, 7, 8, 10, 11, 13}
AddHandler ganttControl.CustomDrawTask, Sub(sender, e)
    Dim taskId As Integer = Convert.ToInt32(e.Node.GetValue("Id"))
    If tasks.Contains(taskId) Then
        e.Appearance.BackColor = DXSkinColors.FillColors.Warning
        e.Appearance.ProgressColor = DXSkinColors.FillColors.Warning
    End If
End Sub
AddHandler ganttControl.CustomDrawTaskDependency, Sub(sender, e)
    Dim predecessorId As Integer = Convert.ToInt32(e.PredecessorNode.GetValue("Id"))
    Dim successorId As Integer = Convert.ToInt32(e.SuccessorNode.GetValue("Id"))
    If tasks.Contains(predecessorId) AndAlso tasks.Contains(successorId) Then
        e.Appearance.BackColor = DXSkinColors.FillColors.Warning
    End If
End Sub

See Also

GanttControl Class

GanttControl Members

DevExpress.XtraGantt Namespace