windowsforms-devexpress-dot-xtrascheduler-dot-schedulercontrol-ed2b3dab.md
Enables visible resources to be painted according to certain conditions.
Namespace : DevExpress.XtraScheduler
Assembly : DevExpress.XtraScheduler.v25.2.dll
NuGet Package : DevExpress.Win.Scheduler
public event QueryResourceColorSchemaEventHandler QueryResourceColorSchema
Public Event QueryResourceColorSchema As QueryResourceColorSchemaEventHandler
The QueryResourceColorSchema event's data class is QueryResourceColorSchemaEventArgs. The following properties provide information specific to this event:
| Property | Description |
|---|---|
| Resource | Gets the resource for which the color schema is queried. |
| ResourceColorIndex | Gets the index of the processed resource’s color schema in a SchedulerColorSchemaCollection collection. |
| ResourceColorSchema | Gets or sets a color schema to be used for a visible resource coloring. |
By default, if you change a set of visible resources (for example, by using resource filter controls) the collection of resource color schemas will remain unchanged (SchedulerControl.GetResourceColorSchemasCopy), i.e. the same color schemas in the same order will be used to paint resources newly selected for display in the scheduler.
However, you can assign a specific color schema to each resource to be displayed. To do this, handle the QueryResourceColorSchema event.
The QueryResourceColorSchema event is raised before a resource to be displayed in the scheduler is painted. The event parameter’s QueryResourceColorSchemaEventArgs.Resource property provides information on a processed resource. To associate this resource with a required color schema, use the QueryResourceColorSchemaEventArgs.ResourceColorSchema property.
The QueryResourceColorSchema event can be helpful, if it is required to paint resources according to certain conditions (for example, to highlight a selected resource or specify a certain color schema for a resource, depending on its custom field value, etc.).
This example demonstrates how to link a specific SchedulerColorSchema to each visible resource.
Call the SchedulerControl.GetResourceColorSchemasCopy method to obtain a collection of color schemas that are currently available for resource coloring (according to the currently active skin) and handle the SchedulerControl.QueryResourceColorSchema event to associate a specific color schema from the obtained collection to each resource displayed in the scheduler control.
using DevExpress.XtraScheduler;
using System.Collections.Generic;
// ...
namespace QueryResourceColorSchema {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
AddResources();
// Get copies of color schemas that are curremnty used to paint resources.
PrepareResourceColorSchemas();
schedulerControl1.LookAndFeel.StyleChanged += new EventHandler(LookAndFeel_StyleChanged);
}
void LookAndFeel_StyleChanged(object sender, EventArgs e) {
// Get copies of color schemas to be used to paint resources
// after the active skin has been changed.
PrepareResourceColorSchemas();
schedulerControl1.ActiveView.LayoutChanged();
}
// ...
Dictionary<object, SchedulerColorSchema> resourceColorSchemas =
new Dictionary<object, SchedulerColorSchema>();
private void PrepareResourceColorSchemas() {
this.resourceColorSchemas.Clear();
int count = Resources.Count;
SchedulerColorSchemaCollection currentColorSchemas =
schedulerControl1.GetResourceColorSchemasCopy();
int schemaCount = currentColorSchemas.Count;
for (int i = 0; i < count; i++) {
Resource resource = schedulerControl1.Storage.Resources[i];
this.resourceColorSchemas.Add(resource.Id, currentColorSchemas[i % schemaCount]);
}
}
private void schedulerControl1_QueryResourceColorSchema(object sender,
QueryResourceColorSchemaEventArgs e) {
object key = e.Resource.Id;
if (this.resourceColorSchemas.ContainsKey(key))
e.ResourceColorSchema = this.resourceColorSchemas[key];
}
}
}
Imports DevExpress.XtraScheduler
Imports System.Collections.Generic
' ...
Namespace QueryResourceColorSchema
Partial Public Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
AddResources()
' Get copies of color schemas that are curremnty used to paint resources.
PrepareResourceColorSchemas()
AddHandler schedulerControl1.LookAndFeel.StyleChanged, AddressOf LookAndFeel_StyleChanged
End Sub
Private Sub LookAndFeel_StyleChanged(ByVal sender As Object, ByVal e As EventArgs)
' Get copies of color schemas to be used to paint resources after the active skin has been changed.
PrepareResourceColorSchemas()
schedulerControl1.ActiveView.LayoutChanged()
End Sub
Private resourceColorSchemas As Dictionary(Of Object, SchedulerColorSchema) = _
New Dictionary(Of Object, SchedulerColorSchema)()
' ...
Private Sub PrepareResourceColorSchemas()
Me.resourceColorSchemas.Clear()
Dim count As Integer = Resources.Count
Dim currentColorSchemas As SchedulerColorSchemaCollection = _
schedulerControl1.GetResourceColorSchemasCopy()
Dim schemaCount As Integer = currentColorSchemas.Count
For i As Integer = 0 To count - 1
Dim resource As Resource = schedulerControl1.Storage.Resources(i)
Me.resourceColorSchemas.Add(resource.Id, currentColorSchemas(i Mod schemaCount))
Next i
End Sub
Private Sub schedulerControl1_QueryResourceColorSchema(ByVal sender As Object, _
ByVal e As QueryResourceColorSchemaEventArgs) _
Handles schedulerControl1.QueryResourceColorSchema
Dim key As Object = e.Resource.Id
If Me.resourceColorSchemas.ContainsKey(key) Then
e.ResourceColorSchema = Me.resourceColorSchemas(key)
End If
End Sub
End Class
End Namespace
See Also