/// <summary> /// Set up the days to display in this WeekScheduleControl. /// </summary> public WeekScheduleControl() { Monday = new DayRegion("Monday"); Tuesday = new DayRegion("Tuesday"); Wednesday = new DayRegion("Wednesday"); Thursday = new DayRegion("Thursday"); Friday = new DayRegion("Friday"); Saturday = new DayRegion("Saturday"); Sunday = new DayRegion("Sunday"); Days.Add(Monday); Days.Add(Tuesday); Days.Add(Wednesday); Days.Add(Thursday); Days.Add(Friday); Days.Add(Saturday); Days.Add(Sunday); }
/// <summary> /// Calculate the time slot bounds. This works out the size and /// shape that days will take up on the screen. This method /// is called from OnPaint only when the property BoundsValidTimeSlot /// is set to false (this property is set to false in cases such as /// when the control has been resized or the date shown has /// changed). /// </summary> protected override void CalculateTimeSlotBounds(Graphics g) { if (Width == 0 || Height == 0) { return; } //TODO: use a bigger font for month name header int monthNameHeight = (int)(RendererCache.Current.Header.GetTextInfo(g, Font).Height * 1.3); int dayNameHeight = (int)(RendererCache.Current.Header.GetTextInfo(g, Font).Height * 1.3); int itemHeight = (int)(RendererCache.Current.Item.GetTextInfo(g, Font).Height * 1.2); int dayHeight = (Height - 1 - dayNameHeight - monthNameHeight) / 6; //take out borders - days will paint right and bottom border themselves int xCurrent = 0; int yCurrent = monthNameHeight + dayNameHeight; int dayWidth = (Width - 1) / 6; int saturdayHeight = (dayHeight) / 2; int sundayHeight = dayHeight - saturdayHeight; // paintBorderWidth = dayWidth * 6 ; // paintBorderHeight = dayHeight * 6 + dayNameHeight ; //clear previous days this.days.Clear(); this.headers.Clear(); //find a monday to start on DateTime currentDay = new DateTime(Date.Year, Date.Month, 1); while (currentDay.DayOfWeek != DayOfWeek.Monday) { currentDay = currentDay.AddDays(-1); } monthHeader = new HeaderRegion(); monthHeader.Name = Date.ToString("MMMM"); monthHeader.Bounds = new Rectangle(xCurrent, 0, dayWidth * 6, monthNameHeight); //set up the day titles int xHeaderCurrent = xCurrent; DateTime headerCurrentDay = currentDay; for (int i = 0; i < 6; i++) { HeaderRegion header = new HeaderRegion(); if (headerCurrentDay.DayOfWeek == DayOfWeek.Saturday || headerCurrentDay.DayOfWeek == DayOfWeek.Sunday) { header.Name = "Saturday/Sunday"; } else { header.Name = headerCurrentDay.DayOfWeek.ToString(); } header.Bounds = new Rectangle(xHeaderCurrent, monthNameHeight, dayWidth, dayNameHeight); headers.Add(header); xHeaderCurrent += dayWidth; headerCurrentDay = headerCurrentDay.AddDays(1); } //set up the days themselves for (int i = 0; i < 42; i++) { DayRegion day = new DayRegion(); day.Date = currentDay; day.IsInCurrentMonth = (currentDay.Month == Date.Month); //if we're up to end of slot, reset it if (day.Date.DayOfWeek == DayOfWeek.Monday) { xCurrent = 0; } //Combine saturday and sunday with split bounds if (currentDay.DayOfWeek == DayOfWeek.Saturday) { day.Bounds = new Rectangle(xCurrent, yCurrent, dayWidth, saturdayHeight); day.TitleBounds = new Rectangle(xCurrent + 1, yCurrent + 1, dayWidth - 2, itemHeight); day.BodyBounds = new Rectangle(day.Bounds.X, day.Bounds.Y + day.TitleBounds.Height, day.Bounds.Width, day.Bounds.Height - day.TitleBounds.Height);// day.Bounds; } else if (currentDay.DayOfWeek == DayOfWeek.Sunday) { day.Bounds = new Rectangle(xCurrent, yCurrent + saturdayHeight, dayWidth, sundayHeight); day.TitleBounds = new Rectangle(xCurrent + 1, yCurrent + saturdayHeight + 1, dayWidth - 2, itemHeight); day.BodyBounds = new Rectangle(day.Bounds.X, day.Bounds.Y + day.TitleBounds.Height, day.Bounds.Width, day.Bounds.Height - day.TitleBounds.Height);// day.Bounds; } else { day.Bounds = new Rectangle(xCurrent, yCurrent, dayWidth, dayHeight); day.TitleBounds = new Rectangle(xCurrent + 1, yCurrent + 1, dayWidth - 2, itemHeight); day.BodyBounds = new Rectangle(day.Bounds.X, day.Bounds.Y + day.TitleBounds.Height, day.Bounds.Width, day.Bounds.Height - day.TitleBounds.Height);// day.Bounds; xCurrent += dayWidth; } if (day.Date.DayOfWeek == DayOfWeek.Sunday) { yCurrent += dayHeight; } days.Add(day); currentDay = currentDay.AddDays(1); } BoundsValidTimeSlot = true; }