Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
obj/
.vs/
bin/Debug/
*/bin/Debug/
7 changes: 4 additions & 3 deletions TestHarness/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ public Form1()
{
InitializeComponent();

CalendarItem item = new CalendarItem( this.calendar1, DateTime.Now, DateTime.Now, "TEST" );

_items.Add( item );
CalendarItem item = new CalendarItem(this.calendar1, new DateTime(2020, 4, 24, 18, 0, 0), new DateTime(2020, 4, 25, 12, 0, 0), "TEST");
calendar1.Items.Add(item);
calendar1.SetRenderHourRange(9, 20);

//_items.Add(item);
}

#region Calendar Methods
Expand Down
10 changes: 6 additions & 4 deletions WindowsFormsCalendar/CalendarDay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,9 @@ internal void SetOverflowStartSelected(bool selected)
/// <summary>
/// Updates the value of <see cref="TimeUnits"/> property
/// </summary>
internal void UpdateUnits()
/// <param name="startHour">the number of hour which is the start the units. </param>
/// <param name="endHour">the number of the hour which is the end of the units. </param>
internal void UpdateUnits(int startHour = 0, int endHour = 24)
{
int factor = 0;

Expand All @@ -294,9 +296,9 @@ internal void UpdateUnits()
default: throw new NotImplementedException("TimeScale not supported");
}

_timeUnits = new CalendarTimeScaleUnit[24 * factor];
int hourSum = 0;
_timeUnits = new CalendarTimeScaleUnit[(endHour - startHour) * factor];

int hourSum = startHour;
int minSum = 0;

for (int i = 0; i < _timeUnits.Length; i++)
Expand Down
12 changes: 9 additions & 3 deletions WindowsFormsCalendar/Renderers/CalendarRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -486,10 +486,15 @@ public int GetTimeY(TimeSpan time)
CalendarDay fisrtDay = Calendar.Days[0];
CalendarTimeScaleUnit firstUnit = fisrtDay.TimeUnits[0];
double duration = Convert.ToDouble(firstUnit.Duration.TotalMinutes);
double totalmins = time.TotalMinutes;
double basemins = Calendar.StartRenderHour * 60;
double totalmins = time.TotalMinutes - basemins;
int unitIndex = Convert.ToInt32(Math.Floor(totalmins / duration));
double module = Convert.ToInt32(Math.Floor(totalmins % duration));

if(unitIndex >= Calendar.Days[0].TimeUnits.Length)
{
unitIndex = Calendar.Days[0].TimeUnits.Length - 1;
}
CalendarTimeScaleUnit unit = Calendar.Days[0].TimeUnits[unitIndex];

int minuteHeight = Convert.ToInt32(Convert.ToDouble(unit.Bounds.Height) / duration);
Expand Down Expand Up @@ -794,8 +799,9 @@ public void PerformItemsLayout()
DateTime date1 = item.StartDate;
DateTime date2 = item.EndDate;

int indexStart = Convert.ToInt32(Math.Floor(date1.TimeOfDay.TotalMinutes / unitDurationMinutes));
int indexEnd = Convert.ToInt32(Math.Ceiling(date2.TimeOfDay.TotalMinutes / unitDurationMinutes));
int basemin = day.Calendar.StartRenderHour * 60;
int indexStart = Convert.ToInt32(Math.Floor((date1.TimeOfDay.TotalMinutes - basemin) / unitDurationMinutes));
int indexEnd = Convert.ToInt32(Math.Ceiling((date2.TimeOfDay.TotalMinutes - basemin) / unitDurationMinutes));

for (int i = 0; i < day.TimeUnits.Length; i++)
{
Expand Down
20 changes: 18 additions & 2 deletions WindowsFormsCalendar/UserControls/Calendar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,10 @@ public CalendarWeek[] Weeks
get { return _weeks; }
}

internal int StartRenderHour { get; private set; } = 0;

internal int EndRenderHour { get; private set; } = 24;

#endregion

/// <summary>
Expand Down Expand Up @@ -1083,6 +1087,16 @@ public void SetViewRange( DateTime dateStart, DateTime dateEnd )
ViewEnd = dateEnd;
}

public void SetRenderHourRange(int startHour, int endHour)
{
this.StartRenderHour = startHour;
this.EndRenderHour = endHour;
foreach(var day in Days)
{
day.UpdateUnits(startHour, endHour);
}
}

/// <summary>
/// Returns a value indicating if the view range intersects the specified date range.
/// </summary>
Expand Down Expand Up @@ -1391,8 +1405,10 @@ private void UpdateDaysAndWeeks()

_days = new CalendarDay[span.Days];

for( int i = 0; i < Days.Length; i++ )
Days[i] = new CalendarDay( this, ViewStart.AddDays( -preDays + i ), i );
for (int i = 0; i < Days.Length; i++)
{
Days[i] = new CalendarDay(this, ViewStart.AddDays(-preDays + i), i);
}


//Weeks
Expand Down