I need this for 2 different changes.
ON one form i got a week calendar, the other a month calendar.

Was hoping to add 2 buttons previous & next.
To scroll back in time x days, or x days forward.
And similar for the months, but instead of days months.

Can anybody give me a exaple or a method how to get this to work?
Figured it could be done with a loop, but not sure anymore.

Thanks

Recommended Answers

All 2 Replies

For using MonthCalendar control and when you want to go 1 month forward and backward when pressing buttons:

Private Sub button1_Click(sender As Object, e As EventArgs)
    '1 month forward
    Dim [date] As DateTime = monthCalendar1.SelectionStart
    monthCalendar1.SelectionStart = [date].AddMonths(1)
    monthCalendar1.SelectionEnd = monthCalendar1.SelectionStart
End Sub

Private Sub button2_Click(sender As Object, e As EventArgs)
    '1 month backward
    Dim [date] As DateTime = monthCalendar1.SelectionStart
    monthCalendar1.SelectionStart = [date].AddMonths(-1)
    monthCalendar1.SelectionEnd = monthCalendar1.SelectionStart
End Sub

In case if you want use to select only one day, dont forget to set property "monthCalendar1.MaxSelectionCount" to 1 on load time.

Stupid me, completely forgot about the datetimepicker, can make it a lot easier this way.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.