Back to Devexpress

GanttControl.CustomDrawTimescaleColumn Event

windowsforms-devexpress-dot-xtragantt-dot-ganttcontrol-7117af8c.md

latest7.1 KB
Original Source

GanttControl.CustomDrawTimescaleColumn Event

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

Namespace : DevExpress.XtraGantt

Assembly : DevExpress.XtraGantt.v25.2.dll

NuGet Package : DevExpress.Win.Gantt

Declaration

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

Event Data

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

PropertyDescription
CacheProvides access to the drawing surface and a cache of brushes, pens, fonts, and other graphics. Inherited from CustomDrawEventArgs.
ColumnGets the processed column.
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.

The event data class exposes the following methods:

MethodDescription
DefaultDraw()Draws the visual element in its default appearance. Inherited from CustomDrawEventArgs.
DrawBackground()Draws the background.
DrawHeader()Draws the header.
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.
DrawHtml(HtmlTemplate, Action<DxHtmlPainterArgs>)Paints the required HTML template inside an element that raised this event.
GetPosition(DateTime)Returns the position of the column that corresponds to the specified date.

Examples

The code below shows how to display a deadline.

Run Demo: Draw a Deadline

csharp
DateTime deadLine = TaskStorage.GetFinishDateFromTask("Deploy Beta");
ganttControl.CustomDrawTimescaleColumn += (sender, e) => {
    GanttTimescaleColumn column = e.Column;
    if(column.StartDate <= deadLine && column.FinishDate >= deadLine) {
        e.DrawBackground();
        float x = (float)e.GetPosition(deadLine); float width = 4;
        RectangleF deadLineRect = new RectangleF(x, column.Bounds.Y, width, column.Bounds.Height);
        e.Cache.FillRectangle(DXSkinColors.FillColors.Danger, deadLineRect);
        e.DrawHeader();
        e.Handled = true;
    }
};
vb
Dim deadLine As Date = TaskStorage.GetFinishDateFromTask("Deploy Beta")
AddHandler ganttControl.CustomDrawTimescaleColumn, Sub(sender, e)
    Dim column As GanttTimescaleColumn = e.Column
    If column.StartDate <= deadLine AndAlso column.FinishDate >= deadLine Then
        e.DrawBackground()
        Dim x As Single = CSng(e.GetPosition(deadLine))
        Dim width As Single = 4
        Dim deadLineRect As New RectangleF(x, column.Bounds.Y, width, column.Bounds.Height)
        e.Cache.FillRectangle(DXSkinColors.FillColors.Danger, deadLineRect)
        e.DrawHeader()
        e.Handled = True
    End If
End Sub

The code below shows how to draw striplines.

Run Demo: Draw Striplines

csharp
DateTime striplineStart = DateTime.Now.AddHours(5);
DateTime striplineEnd = striplineStart.AddHours(4);
Color striplineColor = Color.FromArgb(128, 255, 224, 166);
ganttControl.CustomDrawTimescaleColumn += (sender, e) => {
    GanttTimescaleColumn column = e.Column;
    float stripLineStartPoint = (float)Math.Max(e.GetPosition(striplineStart), column.Bounds.Left);
    float stripLineEndPoint = (float)Math.Min(e.GetPosition(striplineEnd), column.Bounds.Right);
    e.DrawBackground();
    RectangleF boundsToDraw = new RectangleF(stripLineStartPoint, column.Bounds.Y, stripLineEndPoint - stripLineStartPoint, column.Bounds.Height);
    if(boundsToDraw.Width > 0)
        e.Cache.FillRectangle(striplineColor, boundsToDraw);
    e.DrawHeader();
    e.Handled = true;
};
vb
Dim striplineStart As Date = Date.Now.AddHours(5)
Dim striplineEnd As Date = striplineStart.AddHours(4)
Dim striplineColor As Color = Color.FromArgb(128, 255, 224, 166)
AddHandler ganttControl.CustomDrawTimescaleColumn, Sub(sender, e)
    Dim column As GanttTimescaleColumn = e.Column
    Dim stripLineStartPoint As Single = CSng(Math.Max(e.GetPosition(striplineStart), column.Bounds.Left))
    Dim stripLineEndPoint As Single = CSng(Math.Min(e.GetPosition(striplineEnd), column.Bounds.Right))
    e.DrawBackground()
    Dim boundsToDraw As New RectangleF(stripLineStartPoint, column.Bounds.Y, stripLineEndPoint - stripLineStartPoint, column.Bounds.Height)
    If boundsToDraw.Width > 0 Then
        e.Cache.FillRectangle(striplineColor, boundsToDraw)
    End If
    e.DrawHeader()
    e.Handled = True
End Sub

See Also

Timescale

GanttControl Class

GanttControl Members

DevExpress.XtraGantt Namespace