如何在winforms中以编程方式更改Devexpress XtraScheduler控件约会标签背景颜色?

时间:2017-10-10 04:49:12

标签: .net vb.net winforms devexpress

我正在使用 DevExpress 16 ,使用数据库数据动态安排约会。现在,我成功安排了我的预约。我需要以编程方式更改约会标签背景颜色。

我发现了一些改变约会标签背景颜色的编码,如下所示,

Dim labels As AppointmentLabelCollection = schedulerControl1.Storage.AppointmentStorage.Labels
For i As Integer = 0 To labels.Count - 1
    Dim currentLabel As AppointmentLabel = labels(i)
    If currentLabel.Color = someColor Then
        newApt.LabelId = i
        Exit For
    End If
Next

但是,我无法使用此代码设置背景颜色,它显示如下错误:

Code error

我认为由于 AppointmentStorage 在设计时(在“调度程序”控件的“属性”窗口中)自身禁用了上述错误。请参考下图:

See properties, that appointment->Storage->SchedulerStorage1

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

浏览文档:Appointment Labels and Statuses

  

标签存储在AppointmentStorage.Labels集合中。一个   单个标签由AppointmentLabel对象表示。至   访问标签的显示名称和颜色使用它   UserInterfaceObject.DisplayName和AppointmentLabel.Color属性。

您可以在SchedulerControl.CustomDrawAppointmentBackground事件处理程序中绘制约会的背景,而不是使用约会标签。这是另一种可用于定制皮肤外观的方法。您还可以使用其他自定义绘图事件..

文档示例:

public static void scheduler_CustomDrawAppointmentBackground(object sender, CustomDrawObjectEventArgs e)
{
    AppointmentViewInfo viewInfo = e.ObjectInfo as AppointmentViewInfo;
    // Specify the ratio of a completed task to the entire task.
    double completenessRatio = 0.25 * ((int)(viewInfo.Appointment.ResourceId) % 4);
    // Draw an appointment as usual.
    e.DrawDefault();
    // Draw a background rectangle.
    Rectangle bounds = CalculateEntireAppointmentBounds(viewInfo);
    DrawBackGroundCore(e.Cache, bounds, completenessRatio);
    // Indicate that no default drawing is required.
    e.Handled = true;
}