/// <summary> /// The draw month header. /// </summary> /// <param name="g"> /// The g. /// </param> /// <param name="calMonth"> /// The cal month. /// </param> /// <param name="state"> /// The state. /// </param> public override void DrawMonthHeader(Graphics g, MonthCalendarMonth calMonth, MonthCalendarHeaderState state) { if (calMonth == null || !CheckParams(g, calMonth.TitleBounds)) { return; } // get title bounds Rectangle rect = calMonth.TitleBounds; MonthCalendarDate date = new MonthCalendarDate(this._calendar.CultureCalendar, calMonth.Date); MonthCalendarDate firstVisible = new MonthCalendarDate(this._calendar.CultureCalendar, calMonth.FirstVisibleDate); string month; int year; // gets the month name for the month the MonthCalendarMonth represents and the year string if (firstVisible.Era != date.Era) { month = this._calendar.FormatProvider.GetMonthName(firstVisible.Year, firstVisible.Month); year = firstVisible.Year; } else { month = this._calendar.FormatProvider.GetMonthName(date.Year, date.Month); year = date.Year; } string yearString = this._calendar.UseNativeDigits ? DateMethods.GetNativeNumberString(year, this._calendar.Culture.NumberFormat.NativeDigits, false) : year.ToString(CultureInfo.CurrentUICulture); // get used font Font headerFont = this._calendar.HeaderFont; // create bold font Font boldFont = new Font(headerFont.FontFamily, headerFont.SizeInPoints, FontStyle.Bold); // measure sizes SizeF monthSize = g.MeasureString(month, boldFont); SizeF yearSize = g.MeasureString(yearString, boldFont); float maxHeight = Math.Max(monthSize.Height, yearSize.Height); // calculates the width and the starting position of the arrows int width = (int)monthSize.Width + (int)yearSize.Width + 7; int arrowLeftX = rect.X + 6; int arrowRightX = rect.Right - 6; int arrowY = rect.Y + (rect.Height / 2) - 4; int x = Math.Max(0, rect.X + (rect.Width / 2) + 1 - (width / 2)); int y = Math.Max(0, rect.Y + (rect.Height / 2) + 1 - (((int)maxHeight + 1) / 2)); // set the title month name bounds calMonth.TitleMonthBounds = new Rectangle(x, y, (int)monthSize.Width + 1, (int)maxHeight + 1); // set the title year bounds calMonth.TitleYearBounds = new Rectangle(x + calMonth.TitleMonthBounds.Width + 7, y, (int)yearSize.Width + 1, (int)maxHeight + 1); // generate points for the left and right arrow Point[] arrowLeft = { new Point(arrowLeftX, arrowY + 4), new Point(arrowLeftX + 4, arrowY), new Point(arrowLeftX + 4, arrowY + 8), new Point(arrowLeftX, arrowY + 4) }; Point[] arrowRight = { new Point(arrowRightX, arrowY + 4), new Point(arrowRightX - 4, arrowY), new Point(arrowRightX - 4, arrowY + 8), new Point(arrowRightX, arrowY + 4) }; // get brushes for normal, mouse over and selected RequestState // get title month name and year bounds Rectangle monthRect = calMonth.TitleMonthBounds; Rectangle yearRect = calMonth.TitleYearBounds; // set used fonts Font monthFont = headerFont; Font yearFont = headerFont; // set used brushes Brush monthBrush = InactiveTextBrush, yearBrush = InactiveTextBrush; // adjust brush and font if year selected if (state == MonthCalendarHeaderState.YearSelected) { yearBrush = SelectedTextBrush; yearFont = boldFont; yearRect.Width += 4; } else if (state == MonthCalendarHeaderState.YearActive) { // adjust brush if mouse over year yearBrush = ActiveTextBrush; } // adjust brush and font if month name is selected if (state == MonthCalendarHeaderState.MonthNameSelected) { monthBrush = SelectedTextBrush; monthFont = boldFont; monthRect.Width += 4; } else if (state == MonthCalendarHeaderState.MonthNameActive) { // adjust brush if mouse over month name monthBrush = ActiveTextBrush; } // draws the month name and year string g.DrawString(month, monthFont, monthBrush, monthRect); g.DrawString(yearString, yearFont, yearBrush, yearRect); boldFont.Dispose(); // if left arrow has to be drawn if (calMonth.DrawLeftButton) { // get arrow color var arrowBrush = this._calendar.LeftButtonState == ButtonState.Normal ? InactiveArrowBrush : ActiveArrowBrush; // set left arrow rect this._calendar.SetLeftArrowRect(new Rectangle(rect.X, rect.Y, 15, rect.Height)); // draw left arrow using (GraphicsPath path = new GraphicsPath()) { path.AddLines(arrowLeft); g.FillPath(arrowBrush, path); } } // if right arrow has to be drawn if (calMonth.DrawRightButton) { Brush arrowBrush = this._calendar.RightButtonState == ButtonState.Normal ? InactiveArrowBrush : ActiveArrowBrush; // set right arrow rect this._calendar.SetRightArrowRect(new Rectangle(rect.Right - 15, rect.Y, 15, rect.Height)); // draw arrow using (GraphicsPath path = new GraphicsPath()) { path.AddLines(arrowRight); g.FillPath(arrowBrush, path); } } }
/// <summary> /// Draws the header of a <see cref="MonthCalendarMonth"/>. /// </summary> /// <param name="g"> /// The <see cref="Graphics"/> object used to draw. /// </param> /// <param name="calMonth"> /// The <see cref="MonthCalendarMonth"/> to draw the header for. /// </param> /// <param name="state"> /// The <see cref="MonthCalendarHeaderState"/>. /// </param> public abstract void DrawMonthHeader(Graphics g, MonthCalendarMonth calMonth, MonthCalendarHeaderState state);