Back to Devexpress

CustomDrawObjectEventArgs.Bounds Property

windowsforms-devexpress-dot-xtrascheduler-dot-customdrawobjecteventargs.md

latest5.7 KB
Original Source

CustomDrawObjectEventArgs.Bounds Property

Returns the bounding rectangle of the drawing area.

Namespace : DevExpress.XtraScheduler

Assembly : DevExpress.XtraScheduler.v25.2.dll

NuGet Package : DevExpress.Win.Scheduler

Declaration

csharp
public Rectangle Bounds { get; }
vb
Public ReadOnly Property Bounds As Rectangle

Property Value

TypeDescription
Rectangle

A Rectangle value which specifies the object’s bounding rectangle.

|

Example

The following sample code handles the SchedulerControl.CustomDrawAppointment event to manually paint appointments. The image below shows the result.

View Example

csharp
using DevExpress.XtraScheduler;
using DevExpress.XtraScheduler.Drawing;
using System.Drawing.Drawing2D;
private void schedulerControl1_CustomDrawAppointment(object sender, CustomDrawObjectEventArgs e) {
    TimeLineAppointmentViewInfo tlvi = e.ObjectInfo as TimeLineAppointmentViewInfo;
    // This code works only for the Timeline View.
    if(tlvi != null) {
        Rectangle r = e.Bounds;
        r.Offset(3, 3);
        string[] s = tlvi.Appointment.Subject.Split(' ');

        for(int i = 0; i < s.Length; i++) {
            using(var foreBrush = new SolidBrush(colorArray[i]))
                e.Cache.DrawString(s[i], tlvi.Appearance.Font, foreBrush,
r, StringFormat.GenericDefault);
            SizeF shift = e.Cache.CalcTextSize(s[i] + " ", tlvi.Appearance.Font);
            r.X += (int)shift.Width;
        }
        e.Handled = true;
    }
}
vb
Imports DevExpress.XtraScheduler
Imports DevExpress.XtraScheduler.Drawing
Imports System.Drawing.Drawing2D
Private Sub schedulerControl1_CustomDrawAppointment(ByVal sender As Object, ByVal e As CustomDrawObjectEventArgs) Handles schedulerControl1.CustomDrawAppointment
    Dim tlvi As TimeLineAppointmentViewInfo = TryCast(e.ObjectInfo, TimeLineAppointmentViewInfo)
    ' This code works only for the Timeline View.
    If tlvi IsNot Nothing Then
        Dim r As Rectangle = e.Bounds
        r.Offset(3, 3)
        Dim s() As String = tlvi.Appointment.Subject.Split(" "c)

        For i As Integer = 0 To s.Length - 1
            Using foreBrush = New SolidBrush(colorArray(i))
                e.Cache.DrawString(s(i), tlvi.Appearance.Font, foreBrush, r, StringFormat.GenericDefault)
            End Using
            Dim shift As SizeF = e.Cache.CalcTextSize(s(i) & " ", tlvi.Appearance.Font)
            r.X += CInt(shift.Width)
        Next i
        e.Handled = True
    End If
End Sub

The following code snippets (auto-collected from DevExpress Examples) contain references to the Bounds property.

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-custom-draw-appointments/CS/CustomDrawDemo/Form1.cs#L137

csharp
if(aptViewInfo.Selected) {
    Rectangle r = e.Bounds;
    Brush brRect = aptViewInfo.Status.GetBrush();

winforms-scheduler-resolve-appointment-conflicts/CS/DXApplication1/Form1.cs#L74

csharp
if(isConflict) {
    Rectangle rect = e.Bounds;
    Brush brush = e.Cache.GetSolidBrush(scheduler.DataStorage.Appointments.Labels.GetById(apt.LabelKey).GetColor());

winforms-scheduler-custom-draw-appointments/VB/CustomDrawDemo/Form1.vb#L138

vb
If aptViewInfo.Selected Then
    Dim r As Rectangle = e.Bounds
    Dim brRect As Brush = aptViewInfo.Status.GetBrush()

winforms-scheduler-resolve-appointment-conflicts/VB/DXApplication1/Form1.vb#L63

vb
If isConflict Then
    Dim rect As Rectangle = e.Bounds
    Dim brush As Brush = e.Cache.GetSolidBrush(scheduler.DataStorage.Appointments.Labels.GetById(apt.LabelKey).GetColor())

See Also

CustomDrawObjectEventArgs Class

CustomDrawObjectEventArgs Members

DevExpress.XtraScheduler Namespace