【发布时间】:2015-09-11 20:18:18
【问题描述】:
我的最大多日期选择数是 7,所以我创建了 7 个文本框,以便将每个日期存储到相应的文本框中。 我知道如何获取开始日期和结束日期。日期之间我如何将它们存储在文本框中?
【问题讨论】:
标签: vb.net date monthcalendar
我的最大多日期选择数是 7,所以我创建了 7 个文本框,以便将每个日期存储到相应的文本框中。 我知道如何获取开始日期和结束日期。日期之间我如何将它们存储在文本框中?
【问题讨论】:
标签: vb.net date monthcalendar
MonthCalendar 选择是范围,因此您可以使用使用 AddDays 函数的 Do 循环来确定开始日期和结束日期之间的日期。这是一个假设您有 7 个具有以下命名约定的文本框的示例:txtDate1、txtDate2、txtDate3 等。
'First Date
txtDate1.Text = MonthCalendar1.SelectionStart.ToShortDateString()
Dim intCursor As Integer = 1
'Keep adding days to the starting date until you've reached the end.
Do Until MonthCalendar1.SelectionStart.Date.AddDays((intCursor)) >= MonthCalendar1.SelectionEnd.Date
Dim dteTarget As Date = MonthCalendar1.SelectionStart.Date.AddDays((intCursor))
'Casts the Textbox using a naming convention: txtDate1, txtDate2, txtDate3, etc.
CType(Me.Controls("txtDate" & (intCursor + 1).ToString()), TextBox).Text = dteTarget.ToShortDateString()
intCursor += 1
Loop
'If the end date is not the same as the start date then add that.
If MonthCalendar1.SelectionEnd.Date <> MonthCalendar1.SelectionStart.Date Then
CType(Me.Controls("txtDate" & (intCursor + 1).ToString()), TextBox).Text = MonthCalendar1.SelectionEnd.Date.ToShortDateString()
End If
【讨论】: