检测月份日历C#中的月份已更改

时间:2010-10-14 01:09:35

标签: c# winforms

C#中有一个MonthCalender

有2个按钮可供选择月份

1月,2月等等..

无论如何,我可以检测到用户改变了月份?

2 个答案:

答案 0 :(得分:3)

试试这个

private int MonthValue = 0;
private bool bChanged = false;
private void Form1_Load(object sender, EventArgs e)
{
    MonthValue = monthCalendar1.TodayDate.Month;
}
private void monthCalendar1_DateChanged(object sender, DateRangeEventArgs e)
{

    if (MonthValue != monthCalendar1.SelectionStart.Month)
    {
        //changed
        bChanged = true;
        MonthValue = monthCalendar1.SelectionStart.Month;
    }
    else
    {
        //not changed
        bChanged = false;
    }
}

答案 1 :(得分:0)

在日历控件上使用OnVisibleMonthChanged并创建如下事件:

protected void Calendar1_VisibleMonthChanged(object sender, MonthChangedEventArgs e)
        {
            // Further processing goes here
        }