How to get the selected date of a MonthCalendar control in C#

后端 未结 5 699
我寻月下人不归
我寻月下人不归 2020-12-28 13:46

How to get the selected date of a MonthCalendar control in C# (Window forms)

5条回答
  •  -上瘾入骨i
    2020-12-28 13:57

    Using SelectionRange you will get the Start and End date.

    private void monthCalendar1_DateSelected(object sender, DateRangeEventArgs e)
    {
        var startDate = monthCalendar1.SelectionRange.Start.ToString("dd MMM yyyy");
        var endDate = monthCalendar1.SelectionRange.End.ToString("dd MMM yyyy");
    }
    

    If you want to update the maximum number of days that can be selected, then set MaxSelectionCount property. The default is 7.

    // Only allow 21 days to be selected at the same time.
    monthCalendar1.MaxSelectionCount = 21;
    

提交回复
热议问题