Back to Devexpress

GanttControl.CustomPrintTask Event

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

latest13.9 KB
Original Source

GanttControl.CustomPrintTask Event

Fires before a Gantt bar in the chart area is printed. Provides access to the drawing surface and allows you to draw the Gantt bar in a custom way.

Namespace : DevExpress.XtraGantt

Assembly : DevExpress.XtraGantt.v25.2.dll

NuGet Package : DevExpress.Win.Gantt

Declaration

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

Event Data

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

PropertyDescription
AppearanceProvides access to the task’s appearance settings. Inherited from CustomDrawTaskEventArgs.
CacheProvides access to the drawing surface and a cache of brushes, pens, fonts, and other graphics. Inherited from CustomDrawEventArgs.
DurationGets the task duration. Inherited from CustomDrawTaskEventArgs.
FinishDateGets the task finish date. Inherited from CustomDrawTaskEventArgs.
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.
InfoProvides access to view information about the task. Inherited from CustomDrawTaskEventArgs.
NodeGets the processed node. Inherited from CustomDrawTaskEventArgs.
ProgressGets the task progress. Inherited from CustomDrawTaskEventArgs.
StartDateGets the task start date. Inherited from CustomDrawTaskEventArgs.
StateGets the object state: normal, hot tracked, pressed, disabled, or selected. Inherited from CustomDrawTaskEventArgs.

The event data class exposes the following methods:

MethodDescription
DefaultDraw()Draws the visual element in its default appearance. Inherited from CustomDrawEventArgs.
DrawBaseline()Draws the baseline. Inherited from CustomDrawTaskEventArgs.
DrawBaseline(RectangleF)Draws the baseline in the specified bounds. Inherited from CustomDrawTaskEventArgs.
DrawHtml(HtmlTemplate, DxHtmlPainterContext, Action<DxHtmlPainterArgs>)Paints the required HTML template inside an element that raised this event. The context parameter allows you to assign an object that transfers mouse events to template elements. Inherited from CustomDrawTaskEventArgs.
DrawHtml(HtmlTemplate, Action<DxHtmlPainterArgs>)Paints the required HTML template inside an element that raised this event. Inherited from CustomDrawTaskEventArgs.
DrawInsideText()Draws the text inside the bar. Inherited from CustomDrawTaskEventArgs.
DrawLeftLinkPoint()Draws a dependency connection point at the left side of the task. Inherited from CustomDrawTaskEventArgs.
DrawLeftText()Draws the text to the left of the bar. Inherited from CustomDrawTaskEventArgs.
DrawLeftText(RectangleF)Draws the text to the left of the bar within the specified bounds. Inherited from CustomDrawTaskEventArgs.
DrawRightLinkPoint()Draws a dependency connection point at the right side of the task. Inherited from CustomDrawTaskEventArgs.
DrawRightText()Draws the text to the right of the bar. Inherited from CustomDrawTaskEventArgs.
DrawRightText(RectangleF)Draws the text to the left of the bar within the specified bounds. Inherited from CustomDrawTaskEventArgs.
DrawShape()Draws the task shape: bar, summary bar, or milestone. Inherited from CustomDrawTaskEventArgs.
DrawShape(DateTime, DateTime)Draws the task shape (bar, summary bar, or milestone) with an interruption. Inherited from CustomDrawTaskEventArgs.
DrawShape(RectangleF, Single)Draws the task shape: bar, summary bar, or milestone. Inherited from CustomDrawTaskEventArgs.
DrawSplit(RectangleF)Draws a task splitter. Inherited from CustomDrawTaskEventArgs.
GetPosition(DateTime)Returns the horizontal position of the specified date on the timescale. Inherited from CustomDrawTaskEventArgs.

Remarks

Before a project is printed or exported, the control raises the following events that allow you to draw visual elements in a custom way:

  • CustomPrintTask—allows you to draw a Gantt bar. This event is equivalent to the CustomDrawTask event, which allows you to customize a Gantt bar when it is displayed onscreen.

  • CustomPrintTaskDependency—allows you to draw a dependency line. This event is equivalent to the CustomDrawTaskDependency event, which allows you to customize a dependency line when it is displayed onscreen.

  • CustomPrintTimescaleColumn—allows you to draw a timescale column (the header, which displays the date, and the chart area). This event is equivalent to the CustomDrawTimescaleColumn event, which allows you to customize a timescale column when it is displayed onscreen.

Example

The code below shows how to highlight specific tasks and dependencies when the project is printed.

Run Demo: Highlight Tasks and Dependencies

csharp
HashSet<int> tasks = new HashSet<int> { 1, 2, 3, 6, 7, 8, 10, 11, 13 };
ganttControl.CustomPrintTask += (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.CustomPrintTaskDependency += (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.CustomPrintTask, 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.CustomPrintTaskDependency, 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

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the CustomPrintTask event.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-dashboard-custom-items-extension/CS/CustomItemExtension/CustomItems/GanttItem/GanttItemControlProvider.cs#L37

csharp
gantt.CustomDrawTask += Gantt_CustomDrawTask;
gantt.CustomPrintTask += Gantt_CustomPrintTask;
gantt.CustomTaskDisplayText += Gantt_CustomTaskDisplayText;

winforms-dashboard-custom-items-extension/VB/CustomItemExtension/CustomItems/GanttItem/GanttItemControlProvider.vb#L34

vb
AddHandler gantt.CustomDrawTask, AddressOf Gantt_CustomDrawTask
AddHandler gantt.CustomPrintTask, AddressOf Gantt_CustomPrintTask
AddHandler gantt.CustomTaskDisplayText, AddressOf Gantt_CustomTaskDisplayText

See Also

CustomDrawTask

CustomDrawTaskDependency

CustomPrintTaskDependency

CustomDrawTimescaleColumn

CustomPrintTimescaleColumn

Print and Export Gantt Control

GanttControl Class

GanttControl Members

DevExpress.XtraGantt Namespace