MonthCalendar的UserControl

时间:2013-04-12 19:30:21

标签: c# user-controls monthcalendar

我正在尝试修改monthcalendar,但在将用户控件添加到表单之前,VS会冻结。问题是在无限循环中,但我无法找到错误。请帮助

private void SetDayBoxSize()
{
  int bottom = this.Height;

  while (HitTest(1, dayTop).HitArea != HitArea.Date &&
         HitTest(1, dayTop).HitArea != HitArea.PrevMonthDate) dayTop++;

  while (HitTest(1, bottom).HitArea != HitArea.Date &&
    HitTest(1, bottom).HitArea != HitArea.NextMonthDate) bottom--;

  dayBox = new Rectangle();
  dayBox.Size = new Size(this.Width / 7, (bottom - dayTop) / 6);
}

1 个答案:

答案 0 :(得分:0)

您可以使用以下代码解决问题:

private void SetDayBoxSize()
{
  int bottom = this.Height;

  while (HitTest(25, dayTop).HitArea != HitArea.Date &&
         HitTest(25, dayTop).HitArea != HitArea.PrevMonthDate) dayTop++;

  while (HitTest(25, bottom).HitArea != HitArea.Date &&
    HitTest(25, bottom).HitArea != HitArea.NextMonthDate) bottom--;

  dayBox = new Rectangle();
  dayBox.Size = new Size(this.Width / 7, (bottom - dayTop) / 6);
}