Imports System.Collections.Generic Imports Infragistics.Win Imports Infragistics.Win.UltraWinSchedule Imports System.Diagnostics AddHandler Me.dayView.MouseDown, AddressOf dayView_MouseDown Private Sub dayView_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Dim dayView As UltraDayView = sender ' Use the OwnerFromPoint method to hit test for an Owner Dim ownerAtPoint As Owner = dayView.OwnerFromPoint(e.Location) ' Use the DateTimeFromPoint method to hit test for the date and TimeSlot Dim timeSlot As TimeSlot = Nothing Dim dateAtPoint As Nullable(Of DateTime) = dayView.DateTimeFromPoint(e.Location, timeSlot) Dim isInWorkingHours As Boolean = False If Not timeSlot Is Nothing Then If Not ownerAtPoint Is Nothing Then isInWorkingHours = ownerAtPoint.IsInWorkingHours(timeSlot, dateAtPoint.Value) Else ' Create a TimeRange from the WorkDayStartTime and WorkDayEndTime, and then ' use it to determine whether the TimeSlot is within that range Dim dayOfWeek As DayOfWeek = dayView.CalendarInfo.DaysOfWeek(dateAtPoint.Value.DayOfWeek) Dim TimeRange As TimeRange = New TimeRange(dayOfWeek.WorkDayStartTime.TimeOfDay, dayOfWeek.WorkDayEndTime.TimeOfDay) Dim intersects As Boolean = TimeRange.IsInRange(timeSlot) isInWorkingHours = dayOfWeek.IsWorkDay AndAlso intersects End If Dim timeSlotRange As TimeRange = TimeRange.FromTimeSlot(timeSlot, False) Dim notString As String = IIf(isInWorkingHours = False, "not ", String.Empty) Console.WriteLine(String.Format("The {0} time range is {1}within the working hour range.", timeSlotRange.ToString(True), notString)) End If End Sub
using System.Collections.Generic; using Infragistics.Win; using Infragistics.Win.UltraWinSchedule; using System.Diagnostics; this.dayView.MouseDown += new MouseEventHandler(dayView_MouseDown); void dayView_MouseDown(object sender, MouseEventArgs e) { UltraDayView dayView = sender as UltraDayView; // Use the OwnerFromPoint method to hit test for an Owner Owner ownerAtPoint = dayView.OwnerFromPoint( e.Location ); // Use the DateTimeFromPoint method to hit test for the date and TimeSlot TimeSlot timeSlot = null; Nullable<DateTime> dateAtPoint = dayView.DateTimeFromPoint( e.Location, out timeSlot ); bool isInWorkingHours = false; if ( timeSlot != null ) { if ( ownerAtPoint != null ) isInWorkingHours = ownerAtPoint.IsInWorkingHours( timeSlot, dateAtPoint.Value ); else { // Create a TimeRange from the WorkDayStartTime and WorkDayEndTime, and then // use it to determine whether the TimeSlot is within that range DayOfWeek dayOfWeek = dayView.CalendarInfo.DaysOfWeek[dateAtPoint.Value.DayOfWeek]; TimeRange timeRange = new TimeRange( dayOfWeek.WorkDayStartTime.TimeOfDay, dayOfWeek.WorkDayEndTime.TimeOfDay ); bool intersects = timeRange.IsInRange( timeSlot ); isInWorkingHours = dayOfWeek.IsWorkDay && intersects; } TimeRange timeSlotRange = TimeRange.FromTimeSlot( timeSlot, false ); string notString = isInWorkingHours == false ? "not " : string.Empty; Console.WriteLine( string.Format("The {0} time range is {1}within the working hour range.", timeSlotRange.ToString(true), notString) ); } }