Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

How to use Month Calendar Control in VB and C# (.net 2.0). Part 1

Author: Zunnair
Download Source Code : 888_window control.zip

In this simple article you will learn that how we can use Month Calendar control in our application using VB and C# .net 2.0.

 

What is Month Calendar Control?
Month calendar control is provided by dot net which provides a facility to select the date at run time. This is very help full control.
Selected Date:
To get what date is selected by the user we have a property named selection start. This property returns an object of date time class which has the values. The current values which are selected in month calendar control are returned by this property.
To demonstrate this make a window application drag month calendar control, one button and one text box on form. Press the button and you will get values in text box.
Now write the following code on button click event:
 C#
private void btn_getvalue_Click(object sender, EventArgs e)
        {
            DateTime obj = new DateTime();
            string str;
            obj = monthCalendar1.SelectionStart;
            str = obj.ToString();
            textBox1.Text=str;
        }
VB
Private Sub btn_getvalue_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim obj As New DateTime()
        Dim str As String
        obj = monthCalendar1.SelectionStart
        str = obj.ToString()
        textBox1.Text = str
    End Sub
This simple code gets the value which is selected in month calendar control.
Set Current Date in control:
To set the date in month calendar control which should be shown to user in start or to set the today’s date, we have a property named today date. This property takes object of date and time class.
To demonstrate this make a window application drag month calendar control and one button. Press the button.
Now write the following code on button click event:
 C#
private void btn_set_Click(object sender, EventArgs e)
        {
            DateTime obj = new DateTime();
            obj = monthCalendar1.SelectionStart;
            monthCalendar1.TodayDate = obj;
            MessageBox.Show("Date is set");
        }       
VB
Private Sub btn_set_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim obj As New DateTime()
        obj = monthCalendar1.SelectionStart
        monthCalendar1.TodayDate = obj
        MessageBox.Show("Date is set")
    End Sub
This simple code sets the value in control.
Get Current Date in control:
To get which value is set in month calendar control we have a same property named today’s date. This property returns object of date and time class.
To demonstrate this make a window application drag month calendar control and one button. Press the button.
Now write the following code on button click event:
C#
private void btn_get_Click(object sender, EventArgs e)
        {
            DateTime obj = new DateTime();
            obj = monthCalendar1.TodayDate;
            string str;
            str = obj.ToString();
            MessageBox.Show(str);
        }       
VB
Private Sub btn_get_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim obj As New DateTime()
        obj = monthCalendar1.TodayDate
        Dim str As String
        str = obj.ToString()
        MessageBox.Show(str)
    End Sub
This simple code gets the value which is set in control.
Show or Hide Today Date:
This control has a property named show today date. This property provide us a facility that the date set in calendar control, should be shown at bottom of the control or not. It also tells that it is being shown or not. It takes or returns Boolean.
To demonstrate this make a window application drag month calendar control and one button. Press the button.
Now write the following code on button click event:
C#
private void btn_show_Click(object sender, EventArgs e)
        {
            monthCalendar1.ShowToday = true;
        }
VB
Private Sub btn_show_Click(ByVal sender As Object, ByVal e As EventArgs)
        monthCalendar1.ShowToday = True
    End Sub
To hide write the following code.
C#
private void btn_hide_Click(object sender, EventArgs e)
        {
           monthCalendar1.ShowToday = false;
        }
VB
Private Sub btn_hide_Click(ByVal sender As Object, ByVal e As EventArgs)
        monthCalendar1.ShowToday = false;
    End Sub
 
Show or Hide Week Numbers:
To show or hide the week number of the year at the left of each row month calendar control provides a property named show week numbers. This property takes Boolean. It also tells that week numbers are shown or not. It returns Boolean.
To demonstrate this make a window application drag month calendar control and one button. Press the button.
Now write the following code on button click event:
C#
private void btn_showweek_Click(object sender, EventArgs e)
        {
            monthCalendar1.ShowWeekNumbers = true;
        }
VB
Private Sub btn_showweek_Click(ByVal sender As Object, ByVal e As EventArgs)
        monthCalendar1.ShowWeekNumbers = True
    End Sub
This simple code shows the week numbers.
To hide week numbers write the following code.
C#
private void btn_showweek_Click(object sender, EventArgs e)
        {
            monthCalendar1.ShowWeekNumbers = false;
        }
VB
Private Sub btn_showweek_Click(ByVal sender As Object, ByVal e As EventArgs)
        monthCalendar1.ShowWeekNumbers = false
    End Sub
This simple code hides the week numbers.
Now write the following code on FORM LOAD event:
C#
private void Form1_Load(object sender, EventArgs e)
        {
            this.Text = "DEVASP Month Calendar APPLICATION";
            notifyIcon1.Visible = true;
        }     
VB
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
        Me.Text = "DEVASP Month Calendar APPLICATION"
        notifyIcon1.Visible = true
    End Sub
 
This simple article tells that how we can use Month Calendar control in our application using VB and C# .net 2.0.

 

Article Comments
Hi Zunnair,

That was a good article. I am curious about an issue relating to todaydate. Eg. On the calendar days , it has a circle wrapped around a particular date. How to stop that as well. Please help. Thanks.

Posted on 11/29/2009 11:06:20 PM by Lennie Kuah

Hi Lennie kuah,

Thanks for you appreciation, for your circle problem use this single line of code

monthCalendar1.ShowTodayCircle = false;

Thanks.

Posted on 11/30/2009 4:13:01 AM by zunnair

The article was useful.But I am facing another problem here.
I want to use month calendar tool in my project.The thing is,when I click on the date,I would want an excel file to open up.Is that possible?If so,what is the code..

Thanks..

Posted on 1/20/2010 8:58:14 PM by tqah

hi zunnair it is a really useful for me for my project, even i used it.
now i wanna just implement the thing that i need the dates in multi text box by clicking but dates should be equal to number of getting it. the value should not be repeated and previous one should not be bigger then current date.

hope u understand my prob very well, and expecting of reply as soon as posible

Posted on 3/14/2010 7:33:51 PM by dharmik trivedi

dis is a very nice and clear solution given

Posted on 8/27/2010 8:55:49 AM by bhavani

very nice solution

Posted on 8/27/2010 8:56:36 AM by bhavani

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< How to use Date Time Picker Control in VB and C# (.net 2.0).

Disclaimer - Privacy
© 2002-2017 DevASP.net