Imports Infragistics.Win Imports Infragistics.Win.UltraWinSchedule Imports Infragistics.Win.UltraWinSchedule.MonthViewSingle Private Function GetLastVisibleDay() As Infragistics.Win.UltraWinSchedule.Day ' If the specified control is null, being disposed of, ' or has been disposed of, return Nothing ' If Me.ultraMonthViewSingle1 Is Nothing Or Me.ultraMonthViewSingle1.Disposing Or Me.ultraMonthViewSingle1.IsDisposed Then Return Nothing ' If the FirstVisibleDay property is null, we can't continue, so return Nothing If Me.ultraMonthViewSingle1.FirstVisibleDay Is Nothing Then Return Nothing Dim lastDay As DateTime ' If there is only one visible day of the week, we can determine ' the last visible day by adding weeks to the FirstVisibleDay's date ' The number of weeks we add is the value of the VisibleWeeks ' property minus one. If Me.GetNumberOfVisibleDaysOfWeek() = 1 Then ' If there is only one visible week, and only one visible day, ' we know that the last visible day is the same as the first, ' so we can early out by returning the FirstVisibleDay. If Me.ultraMonthViewSingle1.VisibleWeeks = 1 Then Return Me.ultraMonthViewSingle1.FirstVisibleDay ' Add weeks to the date of the FirstVisibleDay lastDay = Me.ultraMonthViewSingle1.FirstVisibleDay.Date.AddDays((Me.ultraMonthViewSingle1.VisibleWeeks - 1) * 7) ' Create the Day object and return it note that we pass true to the 'createIfNull' ' parameter, to ensure that the Day object is created Return Me.ultraMonthViewSingle1.CalendarInfo.GetDay(lastDay, True) End If ' Get the date of the first visible day displayed by the control Dim firstDay As DateTime = Me.ultraMonthViewSingle1.FirstVisibleDay.Date ' Determine the first day of the week displayed by the control Dim dayOfWeek As System.DayOfWeek = firstDay.DayOfWeek ' Determine the DayOfWeek of the last visible day of the week displayed by the control ' ' Start with the day that is exactly one week from the first visible day, ' then go backwards until we hit a day whose corresponding DayOfWeek ' object is visible lastDay = firstDay.AddDays(7) Dim i As Integer For i = 1 To 6 lastDay = lastDay.AddDays(-1) If Me.ultraMonthViewSingle1.CalendarInfo.DaysOfWeek(lastDay.DayOfWeek).Visible Then Exit For Next ' Now we have the date of the last visible day in the same week, ' as the first visible day, so now we need to add weeks to it to get ' the very last day displayed by the control. lastDay = lastDay.AddDays((Me.ultraMonthViewSingle1.VisibleWeeks - 1) * 7) ' Create the Day object and return it note that we pass true to the 'createIfNull' ' parameter, to ensure that the Day object is created Return Me.ultraMonthViewSingle1.CalendarInfo.GetDay(lastDay, True) End Function Private Function GetNumberOfVisibleDaysOfWeek() As Integer '-------------------------------------------------------------------------------- ' Returns the number of visible days of the week displayed by the control '-------------------------------------------------------------------------------- ' If the specified control is null, being disposed of, ' or has been disposed of, return 0 ' If Me.ultraMonthViewSingle1 Is Nothing Or Me.ultraMonthViewSingle1.Disposing Or Me.ultraMonthViewSingle1.IsDisposed Then Return 0 ' Now iterate the CalendarInfo object's DaysOfWeek collection, ' and increment a counter each time we hit a DayOfWeek ' object whose Visible property is true. Dim count As Integer = 0 Dim dayOfWeek As Infragistics.Win.UltraWinSchedule.DayOfWeek For Each dayOfWeek In Me.ultraMonthViewSingle1.CalendarInfo.DaysOfWeek If dayOfWeek.Visible Then count += 1 Next ' Return the accumulated total of visible DayOfWeek objects Return count End Function
using Infragistics.Win; using Infragistics.Win.UltraWinSchedule; using Infragistics.Win.UltraWinSchedule.MonthViewSingle; using System.Diagnostics; private Infragistics.Win.UltraWinSchedule.Day GetLastVisibleDay() { // If the specified control is null, being disposed of, // or has been disposed of, return null // if ( this.ultraMonthViewSingle1 == null || this.ultraMonthViewSingle1.Disposing || this.ultraMonthViewSingle1.IsDisposed ) return null; // If the FirstVisibleDay property is null, we can't continue, so return null if ( this.ultraMonthViewSingle1.FirstVisibleDay == null ) return null; DateTime lastDay; // If there is only one visible day of the week, we can determine // the last visible day by adding weeks to the FirstVisibleDay's date // The number of weeks we add is the value of the VisibleWeeks // property minus one. if ( this.GetNumberOfVisibleDaysOfWeek() == 1 ) { // If there is only one visible week, and only one visible day, // we know that the last visible day is the same as the first, // so we can early out by returning the FirstVisibleDay. if ( this.ultraMonthViewSingle1.VisibleWeeks == 1 ) return this.ultraMonthViewSingle1.FirstVisibleDay; // Add weeks to the date of the FirstVisibleDay lastDay = this.ultraMonthViewSingle1.FirstVisibleDay.Date.AddDays( (double)( (this.ultraMonthViewSingle1.VisibleWeeks - 1) * 7 ) ); // Create the Day object and return it; note that we pass true to the 'createIfNull' // parameter, to ensure that the Day object is created return this.ultraMonthViewSingle1.CalendarInfo.GetDay( lastDay, true ); } // Get the date of the first visible day displayed by the control DateTime firstDay = this.ultraMonthViewSingle1.FirstVisibleDay.Date; // Determine the first day of the week displayed by the control System.DayOfWeek dayOfWeek = firstDay.DayOfWeek; // Determine the DayOfWeek of the last visible day of the week displayed by the control // // Start with the day that is exactly one week from the first visible day, // then go backwards until we hit a day whose corresponding DayOfWeek // object is visible lastDay = firstDay.AddDays( 7.0F ); for ( int i = 1; i < 7; i ++ ) { lastDay = lastDay.AddDays( (double)( -1 ) ); if ( this.ultraMonthViewSingle1.CalendarInfo.DaysOfWeek[ lastDay.DayOfWeek ].Visible ) break; } // Now we have the date of the last visible day in the same week, // as the first visible day, so now we need to add weeks to it to get // the very last day displayed by the control. lastDay = lastDay.AddDays( (double)( (this.ultraMonthViewSingle1.VisibleWeeks - 1) * 7 ) ); // Create the Day object and return it; note that we pass true to the 'createIfNull' // parameter, to ensure that the Day object is created return this.ultraMonthViewSingle1.CalendarInfo.GetDay( lastDay, true ); } private int GetNumberOfVisibleDaysOfWeek() { //-------------------------------------------------------------------------------- // // Returns the number of visible days of the week displayed by the control // //-------------------------------------------------------------------------------- // If the specified control is null, being disposed of, // or has been disposed of, return 0 // if ( this.ultraMonthViewSingle1 == null || this.ultraMonthViewSingle1.Disposing || this.ultraMonthViewSingle1.IsDisposed ) return 0; // Now iterate the CalendarInfo object's DaysOfWeek collection, // and increment a counter each time we hit a DayOfWeek // object whose Visible property is true. int count = 0; foreach( Infragistics.Win.UltraWinSchedule.DayOfWeek dayOfWeek in this.ultraMonthViewSingle1.CalendarInfo.DaysOfWeek ) { if ( dayOfWeek.Visible ) count ++; } // Return the accumulated total of visible DayOfWeek objects return count; }
Target Platforms: Windows 10, Windows 8.1, Windows 8, Windows 7, Windows Server 2012, Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2