Question How to Use MonthCalendar

otuatail

Active member
Joined
May 25, 2011
Messages
28
Programming Experience
5-10
Hi I thought I only needed to click or double click a day on this controll to change it. Do I need to create a click event and if so (I have installed MSDN for VS2008) can I see what events are available.

Desmond.


Private Sub cmdCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCalculate.Click
Dim Days As Integer
Dim Today As DateTime = DateTime.Now
Today = Today.AddDays(30)
Days = DateDiff(DateInterval.Day, DateFrom.TodayDate, DateTo.TodayDate)
' DateTo & DateFrom are MonthCalendar
End Sub

 
You can use a single MonthCalendar to do this, simply grab the SelectionRange property (the Start & End properties) do the math on those and you get a TimeSpan object:
VB.NET:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Dates As TimeSpan = MonthCalendar1.SelectionRange.End - MonthCalendar1.SelectionRange.Start
        MessageBox.Show(Dates.Days.ToString)
    End Sub
This concept applies to using two DateTimePicker's too (one for the start date and one for the end date).
 
Back
Top