如何在C#中获取MonthCalendar控件的选定日期(Window窗体)
发布于 2010-08-07 12:33:04
“只需将MaxSelectionCount
设置为1,这样用户就不能选择超过一天。然后在SelectionRange.Start.ToString()
中。没有任何可用来显示只有一天的选择。”-- Justin Etheredge
来自here。
发布于 2018-06-27 17:50:13
使用SelectionRange
,您将获得Start
和End
日期。
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");
}
如果要更新可以选择的最大天数,请设置MaxSelectionCount
属性。默认值为7。
// Only allow 21 days to be selected at the same time.
monthCalendar1.MaxSelectionCount = 21;
发布于 2013-02-14 21:55:24
对于那些仍在尝试的人来说,这个链接也帮助了我;它只是把所有的东西都放在了一起:
http://dotnetslackers.com/VB_NET/re-36138_How_To_Get_Selected_Date_from_MonthCalendar_control.aspx
private void MonthCalendar1_DateChanged(object sender, System.Windows.Forms.DateRangeEventArgs e)
{
//Display the dates for selected range
Label1.Text = "Dates Selected from :" + (MonthCalendar1.SelectionRange.Start() + " to " + MonthCalendar1.SelectionRange.End);
//To display single selected of date
//MonthCalendar1.MaxSelectionCount = 1;
//To display single selected of date use MonthCalendar1.SelectionRange.Start/ MonthCalendarSelectionRange.End
Label2.Text = "Date Selected :" + MonthCalendar1.SelectionRange.Start;
}
https://stackoverflow.com/questions/3429128
复制相似问题