/// <summary> /// Draws a box of text /// </summary> /// <param name="e"></param> private void DrawBox(MonthViewBoxEventArgs e) { if (!e.BackgroundColor.IsEmpty) { using (SolidBrush b = new SolidBrush(e.BackgroundColor)) { e.Graphics.FillRectangle(b, e.Bounds); } } if (!e.TextColor.IsEmpty && !string.IsNullOrEmpty(e.Text)) { e.TextColor = Color.White; TextRenderer.DrawText(e.Graphics, e.Text, e.Font != null ? e.Font : Font, e.Bounds, e.TextColor, e.TextFlags); } if (!e.BorderColor.IsEmpty) { using (Pen p = new Pen(e.BorderColor)) { Rectangle r = e.Bounds; r.Width--; r.Height--; e.Graphics.DrawRectangle(p, r); } } }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); e.Graphics.Clear(Color.FromArgb(30, 30, 30)); for (int i = 0; i < Months.Length; i++) { if (Months[i].Bounds.IntersectsWith(e.ClipRectangle)) { #region MonthTitle string title = Months[i].Date.ToString(MonthTitleFormat); MonthViewBoxEventArgs evtTitle = new MonthViewBoxEventArgs(e.Graphics, Months[i].MonthNameBounds, title, Focused ? MonthTitleTextColor : MonthTitleTextColorInactive, Focused ? MonthTitleColor : MonthTitleColorInactive); DrawBox(evtTitle); #endregion #region DayNames for (int j = 0; j < Months[i].DayNamesBounds.Length; j++) { MonthViewBoxEventArgs evtDay = new MonthViewBoxEventArgs(e.Graphics, Months[i].DayNamesBounds[j], Months[i].DayHeaders[j], StringAlignment.Far, ForeColor, DayBackgroundColor); DrawBox(evtDay); } if (Months[i].DayNamesBounds != null && Months[i].DayNamesBounds.Length != 0) { using (Pen p = new Pen(MonthTitleColor)) { int y = Months[i].DayNamesBounds[0].Bottom; e.Graphics.DrawLine(p, new Point(Months[i].Bounds.X, y), new Point(Months[i].Bounds.Right, y)); } } #endregion #region Days foreach (MonthViewDay day in Months[i].Days) { if (!day.Visible) { continue; } MonthViewBoxEventArgs evtDay = new MonthViewBoxEventArgs(e.Graphics, day.Bounds, day.Date.Day.ToString(), StringAlignment.Far, day.Grayed ? DayGrayedText : (day.Selected ? DaySelectedTextColor : ForeColor), day.Selected ? DaySelectedBackgroundColor : DayBackgroundColor); if (day.Date.Equals(DateTime.Now.Date)) { evtDay.BorderColor = TodayBorderColor; } DrawBox(evtDay); } #endregion #region Arrows if (i == 0) { Rectangle r = BackwardButtonBounds; using (Brush b = new SolidBrush(BackwardButtonSelected ? ArrowsSelectedColor : ArrowsColor)) { e.Graphics.FillPolygon(b, new Point[] { new Point(r.Right, r.Top), new Point(r.Right, r.Bottom - 1), new Point(r.Left + r.Width / 2, r.Top + r.Height / 2), }); } } if (i == _forwardMonthIndex) { Rectangle r = ForwardButtonBounds; using (Brush b = new SolidBrush(ForwardButtonSelected ? ArrowsSelectedColor : ArrowsColor)) { e.Graphics.FillPolygon(b, new Point[] { new Point(r.X, r.Top), new Point(r.X, r.Bottom - 1), new Point(r.Left + r.Width / 2, r.Top + r.Height / 2), }); } } #endregion } } }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); e.Graphics.Clear(SystemColors.Window); for (int i = 0; i < Months.Length; i++) { if (Months[i].Bounds.IntersectsWith(e.ClipRectangle)) { #region MonthTitle string title = Months[i].Date.ToString(MonthTitleFormat); MonthViewBoxEventArgs evtTitle = new MonthViewBoxEventArgs(e.Graphics, Months[i].MonthNameBounds, title, Focused ? MonthTitleTextColor : MonthTitleTextColorInactive, Focused ? MonthTitleColor : MonthTitleColorInactive); DrawBox(evtTitle); #endregion #region DayNames for (int j = 0; j < Months[i].DayNamesBounds.Length; j++) { MonthViewBoxEventArgs evtDay = new MonthViewBoxEventArgs(e.Graphics, Months[i].DayNamesBounds[j], Months[i].DayHeaders[j], StringAlignment.Far, ForeColor, DayBackgroundColor); DrawBox(evtDay); } if (Months[i].DayNamesBounds != null && Months[i].DayNamesBounds.Length != 0) { using (Pen p = new Pen(MonthTitleColor)) { int y = Months[i].DayNamesBounds[0].Bottom; e.Graphics.DrawLine(p, new Point(Months[i].Bounds.X, y), new Point(Months[i].Bounds.Right, y)); } } #endregion #region Days foreach (MonthViewDay day in Months[i].Days) { if (!day.Visible) continue; MonthViewBoxEventArgs evtDay = new MonthViewBoxEventArgs(e.Graphics, day.Bounds, day.Date.Day.ToString(), StringAlignment.Far, day.Grayed ? DayGrayedText : (day.Selected ? DaySelectedTextColor : ForeColor), day.Selected ? DaySelectedBackgroundColor : DayBackgroundColor); if (day.Date.Equals(DateTime.Now.Date)) { evtDay.BorderColor = TodayBorderColor; } DrawBox(evtDay); } #endregion #region Arrows if (i == 0) { Rectangle r = BackwardButtonBounds; using (Brush b = new SolidBrush(BackwardButtonSelected ? ArrowsSelectedColor : ArrowsColor)) { e.Graphics.FillPolygon(b, new Point[] { new Point(r.Right, r.Top), new Point(r.Right, r.Bottom - 1), new Point(r.Left + r.Width / 2, r.Top + r.Height / 2), }); } } if (i == _forwardMonthIndex) { Rectangle r = ForwardButtonBounds; using (Brush b = new SolidBrush(ForwardButtonSelected ? ArrowsSelectedColor : ArrowsColor)) { e.Graphics.FillPolygon(b, new Point[] { new Point(r.X, r.Top), new Point(r.X, r.Bottom - 1), new Point(r.Left + r.Width / 2, r.Top + r.Height / 2), }); } } #endregion } } }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); e.Graphics.Clear(SystemColors.Window); for (int i = 0; i < Months.Length; i++) { if (Months[i].Bounds.IntersectsWith(e.ClipRectangle)) { #region MonthTitle string title = Months[i].Date.ToString(MonthTitleFormat); MonthViewBoxEventArgs evtTitle = new MonthViewBoxEventArgs(e.Graphics, Months[i].MonthNameBounds, title, Focused ? MonthTitleTextColor : MonthTitleTextColorInactive, Focused ? MonthTitleColor : MonthTitleColorInactive); DrawBox(evtTitle); #endregion #region Days foreach (MonthViewDay day in Months[i].Days) { if (!day.Visible) { continue; } MonthViewBoxEventArgs evtDay = new MonthViewBoxEventArgs(e.Graphics, day.Bounds, day.Date.Day.ToString(), StringAlignment.Far, day.Grayed ? DayGrayedText : (day.Selected ? DaySelectedTextColor : ForeColor), day.Selected ? DaySelectedBackgroundColor : DayBackgroundColor); if (day.Date.Equals(DateTime.Now.Date)) { evtDay.BorderColor = TodayBorderColor; } else { evtDay.BorderColor = Color.White; } if (EventsDurationByDate != null && //!day.Selected && EventsDurationByDate.ContainsKey(day.Date.Date)) { float percentage = EventsDurationByDate[day.Date.Date] * 100 / (float)(12 * 6000); int boundsWidth = evtDay.Bounds.Width; int boundsHeight = evtDay.Bounds.Height; if (percentage < 1f) { boundsHeight = (int)Math.Ceiling(percentage * evtDay.Bounds.Height); } //boundsWidth = (int)Math.Ceiling(percentage * evtDay.Bounds.Width); if (boundsHeight >= 1) { evtDay.FillBounds = new Rectangle(evtDay.Bounds.X, evtDay.Bounds.Y + evtDay.Bounds.Height - boundsHeight, boundsWidth, boundsHeight); //evtDay.BackgroundColor = Color.GreenYellow; evtDay.FillColor = Color.OrangeRed; } } if (day.Selected) { evtDay.BorderColor = Color.Black; } DrawBox(evtDay); } #endregion #region DayNames for (int j = 0; j < Months[i].DayNamesBounds.Length; j++) { MonthViewBoxEventArgs evtDay = new MonthViewBoxEventArgs(e.Graphics, Months[i].DayNamesBounds[j], Months[i].DayHeaders[j], StringAlignment.Far, ForeColor, DayBackgroundColor); DrawBox(evtDay); } if (Months[i].DayNamesBounds != null && Months[i].DayNamesBounds.Length != 0) { using (Pen p = new Pen(MonthTitleColor)) { int y = Months[i].DayNamesBounds[0].Bottom; e.Graphics.DrawLine(p, new Point(Months[i].Bounds.X, y), new Point(Months[i].Bounds.Right, y)); } } #endregion #region Arrows if (i == 0) { Rectangle r = BackwardButtonBounds; using (Brush b = new SolidBrush(BackwardButtonSelected ? ArrowsSelectedColor : ArrowsColor)) { e.Graphics.FillPolygon(b, new Point[] { new Point(r.Right, r.Top), new Point(r.Right, r.Bottom - 1), new Point(r.Left + r.Width / 2, r.Top + r.Height / 2), }); } } if (i == _forwardMonthIndex) { Rectangle r = ForwardButtonBounds; using (Brush b = new SolidBrush(ForwardButtonSelected ? ArrowsSelectedColor : ArrowsColor)) { e.Graphics.FillPolygon(b, new Point[] { new Point(r.X, r.Top), new Point(r.X, r.Bottom - 1), new Point(r.Left + r.Width / 2, r.Top + r.Height / 2), }); } } #endregion } } }
/// <summary> /// Draws a box of text /// </summary> /// <param name="e"></param> private void DrawBox(MonthViewBoxEventArgs e) { if (!e.BackgroundColor.IsEmpty) { using (SolidBrush b = new SolidBrush(e.BackgroundColor)) { e.Graphics.FillRectangle(b, e.Bounds); } } if (!e.TextColor.IsEmpty && !string.IsNullOrEmpty(e.Text)) { TextRenderer.DrawText(e.Graphics, e.Text, e.Font != null ? e.Font : Font, e.Bounds, e.TextColor, e.TextFlags); } if (!e.BorderColor.IsEmpty) { using (Pen p = new Pen(e.BorderColor)) { Rectangle r = e.Bounds; r.Width--; r.Height--; e.Graphics.DrawRectangle(p, r); } } }