本文整理汇总了C#中System.Windows.Forms.MonthCalendar.GetYearNameRectangles方法的典型用法代码示例。如果您正苦于以下问题:C# MonthCalendar.GetYearNameRectangles方法的具体用法?C# MonthCalendar.GetYearNameRectangles怎么用?C# MonthCalendar.GetYearNameRectangles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.MonthCalendar
的用法示例。
在下文中一共展示了MonthCalendar.GetYearNameRectangles方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DrawSingleMonth
// darws a single part of the month calendar (with one month)
private void DrawSingleMonth(Graphics dc, Rectangle clip_rectangle, Rectangle rectangle, MonthCalendar mc, int row, int col)
{
// cache local copies of Marshal-by-ref internal members (gets around error CS0197)
Size title_size = (Size)((object)mc.title_size);
Size date_cell_size = (Size)((object)mc.date_cell_size);
DateTime current_month = (DateTime)((object)mc.current_month);
DateTime sunday = new DateTime(2006, 10, 1);
// draw the title back ground
DateTime this_month = current_month.AddMonths (row*mc.CalendarDimensions.Width+col);
Rectangle title_rect = new Rectangle(rectangle.X, rectangle.Y, title_size.Width, title_size.Height);
if (title_rect.IntersectsWith (clip_rectangle)) {
dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), title_rect);
// draw the title
string title_text = this_month.ToString ("MMMM yyyy");
dc.DrawString (title_text, mc.bold_font, ResPool.GetSolidBrush (mc.TitleForeColor), title_rect, mc.centered_format);
if (mc.ShowYearUpDown) {
Rectangle year_rect;
Rectangle upRect, downRect;
ButtonState upState, downState;
mc.GetYearNameRectangles (title_rect, row * mc.CalendarDimensions.Width + col, out year_rect, out upRect, out downRect);
dc.FillRectangle (ResPool.GetSolidBrush (SystemColors.Control), year_rect);
dc.DrawString (this_month.ToString ("yyyy"), mc.bold_font, ResPool.GetSolidBrush (Color.Black), year_rect, mc.centered_format);
upState = mc.IsYearGoingUp ? ButtonState.Pushed : ButtonState.Normal;
downState = mc.IsYearGoingDown ? ButtonState.Pushed : ButtonState.Normal;
ControlPaint.DrawScrollButton (dc, upRect, ScrollButton.Up, upState);
ControlPaint.DrawScrollButton (dc, downRect, ScrollButton.Down, downState);
}
// draw previous and next buttons if it's time
if (row == 0 && col == 0)
{
// draw previous button
DrawMonthCalendarButton (
dc,
rectangle,
mc,
title_size,
mc.button_x_offset,
(System.Drawing.Size)((object)mc.button_size),
true);
}
if (row == 0 && col == mc.CalendarDimensions.Width-1)
{
// draw next button
DrawMonthCalendarButton (
dc,
rectangle,
mc,
title_size,
mc.button_x_offset,
(System.Drawing.Size)((object)mc.button_size),
false);
}
}
// set the week offset and draw week nums if needed
int col_offset = (mc.ShowWeekNumbers) ? 1 : 0;
Rectangle day_name_rect = new Rectangle(
rectangle.X,
rectangle.Y + title_size.Height,
(7 + col_offset) * date_cell_size.Width,
date_cell_size.Height);
if (day_name_rect.IntersectsWith (clip_rectangle)) {
dc.FillRectangle (GetControlBackBrush (mc.BackColor), day_name_rect);
// draw the day names
DayOfWeek first_day_of_week = mc.GetDayOfWeek(mc.FirstDayOfWeek);
for (int i=0; i < 7; i++)
{
int position = i - (int) first_day_of_week;
if (position < 0)
{
position = 7 + position;
}
// draw it
Rectangle day_rect = new Rectangle(
day_name_rect.X + ((i + col_offset)* date_cell_size.Width),
day_name_rect.Y,
date_cell_size.Width,
date_cell_size.Height);
dc.DrawString (sunday.AddDays (i + (int) first_day_of_week).ToString ("ddd"), mc.Font, ResPool.GetSolidBrush (mc.TitleBackColor), day_rect, mc.centered_format);
}
// draw the vertical divider
int vert_divider_y = Math.Max(title_size.Height+ date_cell_size.Height-1, 0);
dc.DrawLine (
ResPool.GetPen (mc.ForeColor),
rectangle.X + (col_offset * date_cell_size.Width) + mc.divider_line_offset,
rectangle.Y + vert_divider_y,
rectangle.Right - mc.divider_line_offset,
rectangle.Y + vert_divider_y);
}
// draw the actual date items in the grid (including the week numbers)
//.........这里部分代码省略.........