Click here to Skip to main content
15,881,804 members
Please Sign up or sign in to vote.
1.33/5 (3 votes)
See more:
Hi guys

I want to put in my application (Visual basic.net 2010) an event Calendar.
Can anyone know where I find source code for this.

Thanks in advance
Posted
Comments
Sergey Alexandrovich Kryukov 22-Jan-13 11:49am    
Well, no platform, no UI library or application type tagged, no idea what's the problem. Nothing to talk about, unless you rather use "Improve question", above.
And, are you going to write source code? Or do you think everything should be found?
—SA
joshrduncan2012 22-Jan-13 12:17pm    
My 5.
-JD
Sergey Alexandrovich Kryukov 22-Jan-13 12:29pm    
Thank you very much,
—SA
Kschuler 22-Jan-13 15:10pm    
You need to be more specific. Is this a windows forms project, web site,..etc? If you need some general information you can always try google for some articles to get you started.
CHill60 22-Jan-13 20:51pm    
This comment would get a +5 from me ... it's a helpful comment, it's not a derogatory comment, it's not a sarcastic comment, thank you for reminding me that some of us do just want to help ... without just giving it to them on a plate and without just putting people down.

1 solution

Below are some code snippets from one of my programs. This is not a complete solution. It is an example of one (of many) way to use the MonthCalendar Windows Form control to allow user input and validation of dates. This example uses one MonthCalendar control and moves it to be next to the TextBox that is selected via the associated Button control.

To your Windows Form:
  • Add MonthCalendar WinForms control to your Windows Form using Visual Studio Windows Form Designer named MonthCalendar.
  • Add TextBox WinForms control for start date named txtEffectiveDate
  • Add TextBox WinForms control for stop date named txtExpirationDate
  • Add Button WinForms control to bring up calendar for Start date named btnEffectiveDate
  • Add Button WinForms control to bring up calendar for Stop date named btnExpirationDate
  • Add Button WinForms control to complete transaction named btnOK

' Declare some global variables
VB
' objTextbox is a reference to either the 
' txtEffectiveDate TextBox or the txtExpirationDate TextBox. 
' It is set in Click Event Handler
Dim objTextbox as Textbox 
Dim bError_EffectiveDate as Boolean ' True when Effective Date is invalid
Dim bError_ExpirationDate as Boolean ' True when Expiration Date is invalid

' Event for Date Selected
VB
Private Sub MonthCalendar_DateSelected(ByVal sender As Object, ByVal e As System.Windows.Forms.DateRangeEventArgs) Handles MonthCalendar.DateSelected
    bError_StartTime = False
    bError_StopTime = False
    objDateTextBox.Text = Format$(MonthCalendar.SelectionStart, "MM/dd/yyyy")
    Select Case objDateTextBox.Name
        Case "txtEffectiveDate"
            '
        Case "txtExpirationDate"
            '
        Case Else
            ' Do nothing
    End Select
    Call ToggleCalendarButtons(True)
    btnOK.Enabled = True
    txtStartTime.Focus()
End Sub


' Toggle show or hide the MonthCalendar control
VB
Private Sub ToggleCalendarButtons(ByVal TRUEFALSE As Boolean)
    MonthCalendar.Visible = Not TRUEFALSE
    If Not TRUEFALSE Then
        MonthCalendar.BringToFront()
    End If
    btnEffectiveDate.Enabled = TRUEFALSE
    btnExpirationDate.Enabled = TRUEFALSE
    btnOK.Enabled = TRUEFALSE
    Try
        MonthCalendar.SetDate(CDate(objDateTextBox.Text))
    Catch
    End Try
    objDateTextBox.Focus()
End Sub


' Handle click event for Effective Date and Expiration Date buttons
VB
Private Sub btnEffectiveDate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnEffectiveDate.Click
    btnEffectiveDate.Enabled = False
    If Not MonthCalendar.Visible Then
        MonthCalendar.Location = New Point(btnEffectiveDate.Location.X, btnEffectiveDate.Location.Y)
        objDateTextBox = txtEffectiveDate
        Call ToggleCalendarButtons(False)
    End If
    btnEffectiveDate.Enabled = True
End Sub

Private Sub btnExpirationDate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExpirationDate.Click
    btnExpirationDate.Enabled = False
    If Not MonthCalendar.Visible Then
        MonthCalendar.Location = New Point(btnExpirationDate.Location.X, btnExpirationDate.Location.Y)
        objDateTextBox = txtExpirationDate
        Call ToggleCalendarButtons(False)
    End If
    btnExpirationDate.Enabled = True
End Sub

' Validate date in case use keyed it instead of selecting from the calendar
VB
Private Sub txtExpirationDate_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtExpirationDate.Validating
    If txtExpirationDate.Text.Length > 0 Then
        Try
            txtExpirationDate.Text = Format$(CDate(txtExpirationDate.Text.ToString), "MM/dd/yyyy")
            bError_ExpirationDate = False
        Catch myException As InvalidCastException
            MsgBox(myException.Message, MsgBoxStyle.Exclamation, "Expires Date")
            bError_ExpirationDate = True
        End Try
    End If
End Sub

Private Sub txtEffectiveDate_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtEffectiveDate.Validating
    If txtEffectiveDate.Text.Length > 0 Then
        Try
            txtEffectiveDate.Text = Format$(CDate(txtEffectiveDate.Text.ToString), "MM/dd/yyyy")
            bError_EffectiveDate = False
        Catch myException As InvalidCastException
            MsgBox(myException.Message, MsgBoxStyle.Exclamation, "Effective Date")
            bError_EffectiveDate = True
        End Try
    End If
End Sub
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900