Back to Devexpress

SchedulerControl.CustomDrawAppointmentFlyoutSubject Event

windowsforms-devexpress-dot-xtrascheduler-dot-schedulercontrol-242c3271.md

latest13.7 KB
Original Source

SchedulerControl.CustomDrawAppointmentFlyoutSubject Event

Occurs before displaying the appointment flyout. Follows the SchedulerControl.CustomizeAppointmentFlyout event. Enables you to manually draw the visual elements composing the Subject rectangle without having to do a full default draw.

Namespace : DevExpress.XtraScheduler

Assembly : DevExpress.XtraScheduler.v25.2.dll

NuGet Package : DevExpress.Win.Scheduler

Declaration

csharp
public event CustomDrawAppointmentFlyoutSubjectEventHandler CustomDrawAppointmentFlyoutSubject
vb
Public Event CustomDrawAppointmentFlyoutSubject As CustomDrawAppointmentFlyoutSubjectEventHandler

Event Data

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

PropertyDescription
AppointmentProvides access to an appointment for which the flyout is invoked.
BoundsReturns the bounding rectangle of the drawing area. Inherited from CustomDrawObjectEventArgs.
CacheGets an object which specifies the storage for the pens, fonts and brushes. Use it for custom painting in Scheduler Reports. Inherited from CustomDrawObjectEventArgs.
GraphicsGets an object used for painting. Inherited from CustomDrawObjectEventArgs.
HandledGets or sets whether an event was handled. If it was handled, the default actions are not required. Inherited from CustomDrawObjectEventArgs.
ObjectInfoGets information on the painted element. Inherited from CustomDrawObjectEventArgs.
StatusBoundsGets the location and size of the status line in the flyout’s Subject rectangle.

The event data class exposes the following methods:

MethodDescription
DrawBackgroundDefault()Renders the Subject rectangle background using the default drawing mechanism.
DrawDefault()Renders the element using the default drawing mechanism. Inherited from CustomDrawObjectEventArgs.
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 CustomDrawObjectEventArgs.
DrawHtml(HtmlTemplate, Action<DxHtmlPainterArgs>)Paints the required HTML template inside an element that raised this event. Inherited from CustomDrawObjectEventArgs.
DrawStatusDefault()Renders the status line using the default drawing mechanism.
GetDisplayValue(String)Inherited from CustomDrawObjectEventArgs.
GetValue(String)Inherited from CustomDrawObjectEventArgs.

Remarks

If the SchedulerOptionsCustomization.AllowDisplayAppointmentFlyout property is false , the CustomDrawAppointmentFlyoutSubject event as well as the SchedulerControl.CustomizeAppointmentFlyout event do not occur.

If the SchedulerControl.CustomizeAppointmentFlyout event is handled and the CustomizeAppointmentFlyoutEventArgs.ShowSubject property is set to false , the CustomDrawAppointmentFlyoutSubject event does not occur.

Example

The following code handles the SchedulerControl.CustomDrawAppointmentFlyoutSubject event to draw a status line above the subject text and display a warning message if the status is AppointmentStatusType.Free.

View Example

csharp
void OnSchedulerControlCustomDrawAppointmentFlyoutSubject(object sender, CustomDrawAppointmentFlyoutSubjectEventArgs e) {
    e.Handled = true;
    CustomDrawAppointmentFlyoutSubject(e);
}
void CustomDrawAppointmentFlyoutSubject(CustomDrawAppointmentFlyoutSubjectEventArgs e) {
    AppointmentBandDrawerViewInfoBase viewInfo = (AppointmentBandDrawerViewInfoBase)e.ObjectInfo;
    e.DrawBackgroundDefault();
    CustomDrawAppointmentFlyoutSubject(e.Appointment, viewInfo);
}
void CustomDrawAppointmentFlyoutSubject(Appointment appointment, AppointmentBandDrawerViewInfoBase viewInfo) {
    GraphicsCache cache = viewInfo.Cache;
    StringFormat stringFormat = new StringFormat(viewInfo.View.Appearance.GetStringFormat());
    stringFormat.Alignment = stringFormat.LineAlignment = StringAlignment.Center;
    try {
        // Draw status
        Rectangle statusRect = GetStatusBounds(viewInfo);
        cache.FillRectangle(viewInfo.View.Status.GetBrush(), statusRect);

        if (viewInfo.View.Status.Type == AppointmentStatusType.Free) {
            // Draw a warning
            cache.DrawImage(GetWarningIcon(new Size(statusRect.Height, statusRect.Height)), statusRect.Location);
            cache.DrawString("Status is unacceptable", fontStorage.StatusFont, Brushes.Red, statusRect, stringFormat);
        }
        // Draw subject                        
        cache.DrawString(appointment.Subject, fontStorage.SubjectFont, Brushes.Black, GetSubjectBounds(viewInfo), stringFormat);
    }
    finally {
        stringFormat.Dispose();
    }
}
Rectangle GetSubjectBounds(AppointmentBandDrawerViewInfoBase viewInfo) {
    Rectangle bounds = viewInfo.Bounds;
    if (viewInfo.View.Status.Type == AppointmentStatusType.Free) {
        bounds.Offset(0, 10);
    }
    return bounds;
}
Rectangle GetStatusBounds(AppointmentBandDrawerViewInfoBase viewInfo) {
    Rectangle bounds = Rectangle.Inflate(viewInfo.Bounds, -1, -1);
    if (viewInfo.View.Status.Type == AppointmentStatusType.Free) {
        bounds.Height = 20;
    }
    else {
        bounds.Height = 5;
    }
    return bounds;
}
Image GetWarningIcon(Size size) {
    using (Stream stream = AppAssembly.GetManifestResourceStream("CustomAppointmentFlyoutExample.warning.svg")) {
        var paletteProvider = SvgPaletteHelper.GetSvgPalette(schedulerControl1.LookAndFeel, ObjectState.Selected);
        return SvgBitmap.FromStream(stream).Render(size, paletteProvider);
    }
}
static readonly Assembly AppAssembly = Assembly.GetExecutingAssembly();
vb
Private Sub OnSchedulerControlCustomDrawAppointmentFlyoutSubject(ByVal sender As Object, ByVal e As CustomDrawAppointmentFlyoutSubjectEventArgs)
    e.Handled = True
    CustomDrawAppointmentFlyoutSubject(e)
End Sub
Private Sub CustomDrawAppointmentFlyoutSubject(ByVal e As CustomDrawAppointmentFlyoutSubjectEventArgs)
    Dim viewInfo As AppointmentBandDrawerViewInfoBase = CType(e.ObjectInfo, AppointmentBandDrawerViewInfoBase)
    e.DrawBackgroundDefault()
    CustomDrawAppointmentFlyoutSubject(e.Appointment, viewInfo)
End Sub
Private Sub CustomDrawAppointmentFlyoutSubject(ByVal appointment As Appointment, ByVal viewInfo As AppointmentBandDrawerViewInfoBase)
    Dim cache As GraphicsCache = viewInfo.Cache
    Dim stringFormat As New StringFormat(viewInfo.View.Appearance.GetStringFormat())
    stringFormat.LineAlignment = StringAlignment.Center
    stringFormat.Alignment = stringFormat.LineAlignment
    Try
        ' Draw status
        Dim statusRect As Rectangle = GetStatusBounds(viewInfo)
        cache.FillRectangle(viewInfo.View.Status.GetBrush(), statusRect)

        If viewInfo.View.Status.Type = AppointmentStatusType.Free Then
            ' Draw a warning
            cache.DrawImage(GetWarningIcon(New Size(statusRect.Height, statusRect.Height)), statusRect.Location)
            cache.DrawString("Status is unacceptable", fontStorage.StatusFont, Brushes.Red, statusRect, stringFormat)
        End If
        ' Draw subject                        
        cache.DrawString(appointment.Subject, fontStorage.SubjectFont, Brushes.Black, GetSubjectBounds(viewInfo), stringFormat)
    Finally
        stringFormat.Dispose()
    End Try
End Sub
Private Function GetSubjectBounds(ByVal viewInfo As AppointmentBandDrawerViewInfoBase) As Rectangle
    Dim bounds As Rectangle = viewInfo.Bounds
    If viewInfo.View.Status.Type = AppointmentStatusType.Free Then
        bounds.Offset(0, 10)
    End If
    Return bounds
End Function
Private Function GetStatusBounds(ByVal viewInfo As AppointmentBandDrawerViewInfoBase) As Rectangle
    Dim bounds As Rectangle = Rectangle.Inflate(viewInfo.Bounds, -1, -1)
    If viewInfo.View.Status.Type = AppointmentStatusType.Free Then
        bounds.Height = 20
    Else
        bounds.Height = 5
    End If
    Return bounds
End Function
Private Function GetWarningIcon(ByVal size As Size) As Image
    Using stream As Stream = AppAssembly.GetManifestResourceStream("CustomAppointmentFlyoutExample.warning.svg")
        Dim paletteProvider = SvgPaletteHelper.GetSvgPalette(schedulerControl1.LookAndFeel, ObjectState.Selected)
        Return SvgBitmap.FromStream(stream).Render(size, paletteProvider)
    End Using
End Function
Private Shared ReadOnly AppAssembly As System.Reflection.Assembly = System.Reflection.Assembly.GetExecutingAssembly()

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the CustomDrawAppointmentFlyoutSubject 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-scheduler-customize-appointment-flyout/CS/CustomAppointmentFlyoutExample/Form1.cs#L132

csharp
if (chkBtnCustomDrawAppointmentFlyoutSubject.Checked)
    schedulerControl1.CustomDrawAppointmentFlyoutSubject += OnSchedulerControlCustomDrawAppointmentFlyoutSubject;
else

winforms-scheduler-customize-appointment-flyout/VB/CustomAppointmentFlyoutExample/Form1.vb#L143

vb
If chkBtnCustomDrawAppointmentFlyoutSubject.Checked Then
    AddHandler schedulerControl1.CustomDrawAppointmentFlyoutSubject, AddressOf OnSchedulerControlCustomDrawAppointmentFlyoutSubject
Else

See Also

SchedulerControl Class

SchedulerControl Members

DevExpress.XtraScheduler Namespace