windowsforms-devexpress-dot-xtrascheduler-dot-schedulercontrol-083bf82a.md
Occurs before the RangeControl has been automatically adjusted when the scheduler active view or start date is changed.
Namespace : DevExpress.XtraScheduler
Assembly : DevExpress.XtraScheduler.v25.2.dll
NuGet Package : DevExpress.Win.Scheduler
public event RangeControlAdjustEventHandler RangeControlAutoAdjusting
Public Event RangeControlAutoAdjusting As RangeControlAdjustEventHandler
The RangeControlAutoAdjusting event's data class is RangeControlAdjustEventArgs. The following properties provide information specific to this event:
| Property | Description |
|---|---|
| RangeMaximum | Gets or sets the end bound of the range that will be available in the RangeControl after it is automatically adjusted. |
| RangeMinimum | Gets or sets the start bound of the range that will be available in the RangeControl after it is automatically adjusted. |
| Scales | Provides access to the collection of scales that will be visible in the RangeControl after it is automatically adjusted. |
Handle the RangeControlAutoAdjusting event to customize auto-adjust settings to be applied to the RangeControl after the scheduler view is changed or the scheduler start date is switched to a date that is beyond the RangeControl’s available time range.
Note
The RangeControlAutoAdjusting event is fired only if the SchedulerOptionsRangeControl.AutoAdjustMode is set to true.
Use the event arguments to customize the RangeControl scales (RangeControlAdjustEventArgs.Scales) and total range boundaries (RangeControlAdjustEventArgs.RangeMinimum, RangeControlAdjustEventArgs.RangeMaximum) to be applied when adjusting the RangeControl. To review the default auto-adjust settings, see the SchedulerOptionsRangeControl.AutoAdjustMode property description.
This example demonstrates how to customize the auto-adjusting settings before they are applied to the RangeControl when an end-user switches the scheduler to the Work-Week or Month view.
SchedulerControl.RangeControlAutoAdjusting event. In this event handler, specify the RangeControl scales and range to be set when the Work-Week or Month view becomes active in the following way:using System;
using System.Windows.Forms;
using DevExpress.XtraScheduler;
using DevExpress.XtraScheduler.Native;
namespace WindowsFormsApplication1 {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
}
private void schedulerControl1_RangeControlAutoAdjusting(object sender,
RangeControlAdjustEventArgs e) {
schedulerControl.OptionsRangeControl.AutoFormatScaleCaptions = true;
SchedulerViewType activeViewType = schedulerControl.ActiveViewType;
if (activeViewType == SchedulerViewType.WorkWeek) {
schedulerControl.OptionsRangeControl.AutoFormatScaleCaptions = false;
e.Scales[4].DisplayFormat = "dddd";
e.Scales[4].Width = 70;
}
if (activeViewType == SchedulerViewType.Month) {
schedulerControl.OptionsRangeControl.AutoFormatScaleCaptions = false;
e.Scales.Clear();
TimeScaleMonth monthScale = new TimeScaleMonth();
monthScale.DisplayFormat = "MMMM yyyy";
e.Scales.Add(monthScale);
TwoWeekTimeScale twoWeekTimeScale = new TwoWeekTimeScale();
twoWeekTimeScale.Width = 120;
e.Scales.Add(twoWeekTimeScale);
e.RangeMinimum = new DateTime(e.RangeMinimum.Year, 1, 1);
e.RangeMaximum = e.RangeMinimum.AddYears(1);
}
}
}
public class TwoWeekTimeScale : TimeScaleFixedInterval {
public TwoWeekTimeScale()
: base(TimeSpan.FromDays(14)) {
}
public override DateTime Floor(DateTime date) {
DateTime startOfWeeek = DateTimeHelper.GetStartOfWeekUI(date,
DateTimeHelper.FirstDayOfWeek);
if (DateTimeHelper.GetWeekOfYear(date) % 2 == 0)
return startOfWeeek.AddDays(-7);
return startOfWeeek;
}
public override string FormatCaption(DateTime start, DateTime end) {
string dateString = "Week {0} - Week {1}";
return String.Format(dateString, DateTimeHelper.GetWeekOfYear(start),
DateTimeHelper.GetWeekOfYear(end.AddTicks(-1)));
}
}
}
Imports Microsoft.VisualBasic
Imports System
Imports System.Windows.Forms
Imports DevExpress.XtraScheduler
Imports DevExpress.XtraScheduler.Native
Namespace WindowsFormsApplication1
Partial Public Class Form1
Inherits Form
Public Sub New()
InitializeComponent()
End Sub
Private Sub schedulerControl1_RangeControlAutoAdjusting(ByVal sender As Object, _
ByVal e As RangeControlAdjustEventArgs) _
Handles schedulerControl.RangeControlAutoAdjusting
schedulerControl.OptionsRangeControl.AutoFormatScaleCaptions = True
Dim activeViewType As SchedulerViewType = schedulerControl.ActiveViewType
If activeViewType = SchedulerViewType.WorkWeek Then
schedulerControl.OptionsRangeControl.AutoFormatScaleCaptions = False
e.Scales(4).DisplayFormat = "dddd"
e.Scales(4).Width = 70
End If
If activeViewType = SchedulerViewType.Month Then
schedulerControl.OptionsRangeControl.AutoFormatScaleCaptions = False
e.Scales.Clear()
Dim monthScale As New TimeScaleMonth()
monthScale.DisplayFormat = "MMMM yyyy"
e.Scales.Add(monthScale)
Dim twoWeekTimeScale As New TwoWeekTimeScale()
twoWeekTimeScale.Width = 120
e.Scales.Add(twoWeekTimeScale)
e.RangeMinimum = New DateTime(e.RangeMinimum.Year, 1, 1)
e.RangeMaximum = e.RangeMinimum.AddYears(1)
End If
End Sub
End Class
Public Class TwoWeekTimeScale
Inherits TimeScaleFixedInterval
Public Sub New()
MyBase.New(TimeSpan.FromDays(14))
End Sub
Public Overrides Overloads Function Floor(ByVal [date] As DateTime) As DateTime
Dim startOfWeeek As DateTime = DateTimeHelper.GetStartOfWeekUI([date], DateTimeHelper.FirstDayOfWeek)
If DateTimeHelper.GetWeekOfYear([date]) Mod 2 = 0 Then
Return startOfWeeek.AddDays(-7)
End If
Return startOfWeeek
End Function
Public Overrides Function FormatCaption(ByVal start As DateTime, ByVal [end] As DateTime) As String
Dim dateString As String = "Week {0} - Week {1}"
Return String.Format(dateString, DateTimeHelper.GetWeekOfYear(start), _
DateTimeHelper.GetWeekOfYear([end].AddTicks(-1)))
End Function
End Class
End Namespace
See Also